Previous Up Next
Request Classes phpHtmlLib Framework Database object


The phpHtmlLib Cache classes

© October 2007, Walter A. Boring IV, Suren Markosian
(phpHtmlLib 3.0.1)

Table of Contents

Cache overview.

The phpHtmlLib framework has many different ways to cache data. You can enable/disable caching globally if you like. You can use caching for database requests, rendered page output or anything you like. There are several classes that help you do caching.

The Cache classes

  • Cache -- the base Cache classes.

  • NoCache -- when caching is disabled this class is used.

  • FileCache -- uses files on disk to cache data.

  • MemcachedCache -- uses memcached to cache data.

  • DataCache -- child of MemcachedCache to show a setup example

  • SessionCache -- used for storing session keys

  • Cache

    By default caching is enabled. If you want to disable it globally, then do this.

      //This will globally force all requests for a
      //Cache object to return the NoCache object.


    The NoCache object is a child of the Cache object to act as a stub. When caching id disabled, the NoCache object is returned for all singleton() method calls. This will ensure that all requests to use the cache goes through NoCache. NoCache::get() will always return false, which should induce a fallback to the more permanent store for the key.

    Here are some samples of using the PostRequestBuilder

      //first disable all caching.
      //$c is now a NoCache object, because caching is globally disabled.
      $c = FileCache::singleton();
      //value will be false.
      $value = $c->get('name');
      //does nothing.
      $c->set('name', 'walt');


    The FileCache object by default will create a directory /tmp/phphtmllib-cache to store all of it's files. Each cache key will map to 1 file on disk with the name as the key.

    You can change the default cache directory if you like.

      //change the default cache dir

    How do I set and get a cache value?

      //get the cache object
      $c = FileCache::singleton();
      $c->set('my_cache_key', $somedata, $sometimeout);
      $data = $c->get('my_cache_key');

    That same api will work for all of the Cache objects.

    Software license

    phpHtmlLib is released under GNU LGPL

    Previous Up Next
    Request Classes phpHtmlLib Framework Database object

    Documentation generated on Thu, 11 Oct 2007 12:05:14 -0700 by phpDocumentor 1.4.0