PEAR Articles
  Home arrow PEAR Articles arrow Page 3 - Caching with PEAR::Cache
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PEAR ARTICLES

Caching with PEAR::Cache
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2004-03-19

    Table of Contents:
  • Caching with PEAR::Cache
  • Installing Pear::Cache
  • Defining the Cache
  • Implementing a Framework
  • Combined Code
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Caching with PEAR::Cache - Defining the Cache


    (Page 3 of 6 )

    Pear::Cache is flexible in that it can cache script results in various ways, such as databases, files and even shared memory. We will pass two arguments when we create an instance of the cache object: the storage type and an array of options.

    Valid storage options are: db, dbx, file, mdb, msession, phplib and shm. For this tutorial we will be storing our cached results as files.

    Each storage mechanism accepts different parameters. The valid options for storing cached data as files are: cache_dir, filename_prefix and max_userdata_linelength.

    The cache_dir option enables us to specify the directory where we want our cached files to be stored.

    The filename_prefix enables us to specify a prefix to add to each cached file generated. This allows us to keep our cache organized while still keeping all cache files in the same directory. It also provides us a way to work around any clashing IDs when we use the generateID method discussed later.

    The max_userdata_linelength is used to specify how much the class' fgets function will read at a time when retrieving cached data. max_userdata_linelength is used primarily for the sake of efficiency.

    While of course you're welcome to experiment with the various options, we won't use filename_prefix or max_userdata_linelength. We’ll keep things simple and set just the directory used to house our cached files.

    Now we can now instantiate the class:

    <?php
    $store_as 
    "file";
    $options = array("cache_dir" =&gtgetcwd() . "/cache");
    $cache = new cache($store_as$options);
    ?>

    More PEAR Articles Articles
    More By bluephoenix


       · For all my proficiency with PHP the need to do command line stuff has so far passed...
       · Dear AllI have defined variables as follow in an data entry formprod1...
       · Dear AllI have defined variables as follow in an data entry formprod1...
       · Essentially all of PHP setup and maintenance is conducted on a command line. You'll...
       · This type of question should really be posed in the forum. There are many people...
       · &quot;Net_Socket is part of the default Pear installation so...&quot;...
       · study
       · i think it's a case to case basis Jayden. what platform are you using?
     

    PEAR ARTICLES ARTICLES

    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR
    - The PEAR Package Tour: PEAR Basics
    - Caching with PEAR::Cache
    - Introduction to PEAR
    - The PEAR ITX Templating System





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT