Home « Server software «
Documentation: shared/cache.php
Class Cache - Speed up things by caching information
The objective of this cache module is to save time. Any other module may use it freely by calling member functions as described in the following example.From within the page that has to cache information:
// the id for the cache combines the script name, plus unique information from within this script
$cache_id = 'my_module/index.php#items_by_date';
// retrieve the information from cache if possible
if(!$text =& Cache::get($cache_id)) {
// else build the page dynamically
$result = Items::list_by_date();
$text = Skin::build_list($result, 'decorated');
// cache information for next request
Cache::put($cache_id, $text, 'items');
}
The cache will be killed in case of updates:
// post a new item
function post($fields) {
// the UPDATE statement here
...
// kill cached items
Cache::clear('items');
}
Note that the cache also takes into account a maximum expiration delay. By default this delay is about one-fifth of 24 hours, but this can be changed while pushing an object into the cache.
Calls to the SQL library are protected because of migration from old versions of the software.
This script is a reference file of this system.
Licence: GNU Lesser General Public License
Auteurs:
- Bernard Paques bernard.paques@bigfoot.com
clear() - Suppress some content from the cache
function clear($topic=NULL)
- $topic=NULL - mixed the topic(s) to be deleted; if NULL, clear all cache entries
get() - Retrieve cached information
function &get($id)
- $id - string the id of the text to be retrieved
- returns string cached information, or NULL if the no accurate information is available for this id
pass_through() - Retrieve cached information and pass it through the browser
function pass_through($id)
- $id - string the id of the text to be retrieved
Voir aussi:
put() - Put something into the cache
function put($id, &$text, $topic='global', $duration=3600)
- $id - string the id of this item
- &$text - string the content to store
- $topic='global' - string the topic related to this item
- $duration=3600 - int the maximum time before expiration, in seconds
setup() - Create tables for the cache
function setup()