[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> Cache.php (sommaire)

(pas de description)

Poids: 356 lignes (11 kb)
Inclus ou requis: 5 fois
Référencé: 0 fois
Nécessite: 2 fichiers
 Cache/Error.php
 PEAR.php

Définit 1 class

Cache:: (15 méthodes):
  Cache()
  _Cache()
  getCaching()
  setCaching()
  get()
  save()
  extSave()
  load()
  getUserdata()
  remove()
  flush()
  isCached()
  isExpired()
  generateID()
  garbageCollection()


Classe: Cache  - X-Ref

Cache is a base class for cache implementations.

The pear cache module is a generic data cache which can be used to
cache script runs. The idea behind the cache is quite simple. If you have
the same input parameters for whatever tasks/algorithm you use you'll
usually get the same output. So why not caching templates, functions calls,
graphic generation etc. Caching certain actions e.g. XSLT tranformations
saves you lots of time.

The design of the cache reminds of PHPLibs session implementation. A
(PHPLib: session) controller uses storage container (PHPLib: ct_*.inc) to save
certain data (PHPLib: session data). In contrast to the session stuff it's up to
you to generate an ID for the data to cache. If you're using the output cache
you might use the script name as a seed for cache::generateID(), if your using the
function cache you'd use an array with all function parameters.

Usage example of the generic data cache:

require_once('Cache.php');

$cache = new Cache('file', array('cache_dir' => 'cache/') );
$id = $cache->generateID('testentry');

if ($data = $cache->get($id)) {
print "Cache hit.<br>Data: $data";

} else {
$data = 'data of any kind';
$cache->save($id, $data);
print 'Cache miss.<br>';
}

WARNING: No File/DB-Table-Row locking is implemented yet,
it's possible, that you get corrupted data-entries under
bad circumstances  (especially with the file container)

Cache($container, $container_options = '')   X-Ref

param: string  Name of container class
param: array   Array with container class options

_Cache()   X-Ref
Pas de description

getCaching()   X-Ref
Returns the current caching state.

return: boolean     The current caching state.

setCaching($state)   X-Ref
Enables or disables caching.

param: boolean     The new caching state.

get($id, $group = 'default')   X-Ref
Returns the requested dataset it if exists and is not expired

param: string  dataset ID
param: string  cache group
return: mixed   cached data or NULL on failure

save($id, $data, $expires = 0, $group = 'default')   X-Ref
Stores the given data in the cache.

param: string  dataset ID used as cache identifier
param: mixed   data to cache
param: integer lifetime of the cached data in seconds - 0 for endless
param: string  cache group
return: boolean

extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default')   X-Ref
Stores a dataset with additional userdefined data.

param: string  dataset ID
param: mixed   data to store
param: string  additional userdefined data
param: mixed   userdefined expire date
param: string  cache group
return: boolean

load($id, $group = 'default')   X-Ref
Loads the given ID from the cache.

param: string  dataset ID
param: string  cache group
return: mixed   cached data or NULL on failure

getUserdata($id, $group = 'default')   X-Ref
Returns the userdata field of a cached data set.

param: string  dataset ID
param: string  cache group
return: string  userdata

remove($id, $group = 'default')   X-Ref
Removes the specified dataset from the cache.

param: string  dataset ID
param: string  cache group
return: boolean

flush($group = 'default')   X-Ref
Flushes the cache - removes all data from it

param: string  cache group, if empty all groups will be flashed
return: integer number of removed datasets

isCached($id, $group = 'default')   X-Ref
Checks if a dataset exists.

Note: this does not say that the cached data is not expired!

param: string  dataset ID
param: string  cache group
return: boolean

isExpired($id, $group = 'default', $max_age = 0)   X-Ref
Checks if a dataset is expired

param: string  dataset ID
param: string  cache group
param: integer maximum age for the cached data in seconds - 0 for endless
return: boolean

generateID($variable)   X-Ref
Generates a "unique" ID for the given value

This is a quick but dirty hack to get a "unique" ID for a any kind of variable.
ID clashes might occur from time to time although they are extreme unlikely!

param: mixed   variable to generate a ID for
return: string  "unique" ID

garbageCollection($force = false)   X-Ref
Calls the garbage collector of the storage object with a certain probability

param: boolean Force a garbage collection run?



Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7