Skip to main content Help Control Panel

Aubagne HipHop

Tout le Hip Hop d'Aubagne et des alentours

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:

clear() - Suppress some content from the cache

function clear($topic=NULL)

This script always clear global objects

get() - Retrieve cached information

function &get($id)

pass_through() - Retrieve cached information and pass it through the browser

function pass_through($id)



Voir aussi:

put() - Put something into the cache

function put($id, &$text, $topic='global', $duration=3600)

The default caching period is 1 hour (actually, 60m*60s = 3,600s)

setup() - Create tables for the cache

function setup()

Tools
Browse the source of this script
Server software