Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Cache_Lite

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5

 Class Cache_Lite

Description

Located in /pear/cache/Lite.php (line 29)

Class Cache_Lite
Direct descendents
Class Description
ClassCache_Lite_Output This class extends Cache_Lite and uses output buffering to get the data to cache.
ClassCache_Lite_File This class extends Cache_Lite and offers a cache system driven by a master file
ClassCache_Lite_Function This class extends Cache_Lite and can be used to cache the result and output of functions/methods
Method Summary
Constructor Cache_Lite Cache_Lite ([array $options = array(NULL)])
Method boolean clean ([string $group = false], [string $mode = 'ingroup'])
Method void extendLife ()
Method string get (string $id, [string $group = 'default'], [boolean $doNotTestCacheValidity = false])
Method void getMemoryCachingState (string $id, [string $group = 'default'], [boolean $doNotTestCacheValidity = false])
Method int lastModified ()
Method void raiseError (string $msg, int $code)
Method boolean remove (string $id, [string $group = 'default'])
Method boolean save (string $data, [string $id = NULL], [string $group = 'default'])
Method void saveMemoryCachingState (string $id, [string $group = 'default'])
Method void setLifeTime (int $newLifeTime)
Method void setOption ( $name,  $value)
Method void setToDebug ()
Variables
int $_automaticCleaningFactor = 0 (line 217)

Disable / Tune the automatic cleaning process

The automatic cleaning process destroy too old (for the given life time) cache files when a new cache file is written.

  1. => no automatic cache cleaning
  2. => systematic cache cleaning
x (integer) > 1 => automatic cleaning randomly 1 times on x cache write

boolean $_automaticSerialization = false (line 204)

Enable / disable automatic serialization

it can be used to save directly datas which aren't strings (but it's slower)

string $_cacheDir = '/tmp/' (line 40)

Directory where to put the cache files (make sure to add a trailing slash)

boolean $_caching = true (line 49)

Enable / disable caching

(can be very usefull for the debug of cached scripts)

boolean $_errorHandlingAPIBreak = false (line 249)

API break for error handling in CACHE_LITE_ERROR_RETURN mode

In CACHE_LITE_ERROR_RETURN mode, error handling was not good because for example save() method always returned a boolean (a PEAR_Error object would be better in CACHE_LITE_ERROR_RETURN mode). To correct this without breaking the API, this option (false by default) can change this handling.

string $_file (line 81)

File name (with path)

boolean $_fileLocking = true (line 67)

Enable / disable fileLocking

(can avoid cache corruption under bad circumstances)

string $_fileName (line 88)

File name (without path)

boolean $_fileNameProtection = true (line 194)

File Name protection

if set to true, you can use any cache id or group name if set to false, it can be faster but cache ids and group names will be used directly in cache file names so be carefull with special characters...

string $_group (line 144)

Current cache group

int $_hashedDirectoryLevel = 0 (line 230)

Nested directory level

Set the hashed directory structure level. 0 means "no hashed directory structure", 1 means "one level of directory", 2 means "two levels"... This option can speed up Cache_Lite only when you have many thousands of cache file. Only specific benchs can help you to choose the perfect value for you. Maybe, 1 or 2 is a good start.

int $_hashedDirectoryUmask = 0700 (line 237)

Umask for hashed directory structure

string $_id (line 137)

Current cache id

int $_lifeTime = 3600 (line 58)

Cache lifetime (in seconds)

If null, the cache is valid forever.

boolean $_memoryCaching = false (line 153)

Enable / Disable "Memory Caching"

NB : There is no lifetime for memory caching !

array $_memoryCachingArray = array() (line 168)

Memory caching array

int $_memoryCachingCounter = 0 (line 175)

Memory caching counter

int $_memoryCachingLimit = 1000 (line 182)

Memory caching limit

boolean $_onlyMemoryCaching = false (line 161)

Enable / Disable "Only Memory Caching" (be carefull, memory caching is "beta quality")

int $_pearErrorMode = CACHE_LITE_ERROR_RETURN (line 130)

Pear error mode (when raiseError is called)

(see PEAR doc)

boolean $_readControl = true (line 108)

Enable / disable read control

If enabled, a control key is embeded in cache file and this key is compared with the one calculated after the reading.

boolean $_readControlType = 'crc32' (line 120)

Type of read control (only if read control is enabled)

Available values are : 'md5' for a md5 hash control (best but slowest) 'crc32' for a crc32 hash control (lightly less safe but faster, better choice) 'strlen' for a length only test (fastest)

int $_refreshTime (line 74)

Timestamp of the last valid cache

boolean $_writeControl = true (line 98)

Enable / disable write control (the cache is read just after writing to detect corrupt entries)

Enable write control will lightly slow the cache writing but not the cache reading Write control can detect some corrupt cache files but maybe it's not a perfect control

Methods
Constructor Cache_Lite (line 280)

Constructor

$options is an assoc. Available options are : $options = array( 'cacheDir' => directory where to put the cache files (string), 'caching' => enable / disable caching (boolean), 'lifeTime' => cache lifetime in seconds (int), 'fileLocking' => enable / disable fileLocking (boolean), 'writeControl' => enable / disable write control (boolean), 'readControl' => enable / disable read control (boolean), 'readControlType' => type of read control 'crc32', 'md5', 'strlen' (string), 'pearErrorMode' => pear error mode (when raiseError is called) (cf PEAR doc) (int), 'memoryCaching' => enable / disable memory caching (boolean), 'onlyMemoryCaching' => enable / disable only memory caching (boolean), 'memoryCachingLimit' => max nbr of records to store into memory caching (int), 'fileNameProtection' => enable / disable automatic file name protection (boolean), 'automaticSerialization' => enable / disable automatic serialization (boolean), 'automaticCleaningFactor' => distable / tune automatic cleaning process (int), 'hashedDirectoryLevel' => level of the hashed directory system (int), 'hashedDirectoryUmask' => umask for hashed directory structure (int), 'errorHandlingAPIBreak' => API break for better error handling ? (boolean) );

  • access: public
Cache_Lite Cache_Lite ([array $options = array(NULL)])
  • array $options: options
clean (line 443)

Clean the cache

if no group is specified all cache files will be destroyed else only cache files of the specified group will be destroyed

  • return: true if no problem
  • access: public
boolean clean ([string $group = false], [string $mode = 'ingroup'])
  • string $group: name of the cache group
  • string $mode: flush cache mode : 'old', 'ingroup', 'notingroup', 'callback_myFunction'
extendLife (line 547)

Extend the life of a valid cache file

see http://pear.php.net/bugs/bug.php?id=6681

  • access: public
void extendLife ()
get (line 314)

Test if a cache is available and (if yes) return it

  • return: data of the cache (else : false)
  • access: public
string get (string $id, [string $group = 'default'], [boolean $doNotTestCacheValidity = false])
  • string $id: cache id
  • string $group: name of the cache group
  • boolean $doNotTestCacheValidity: if set to true, the cache validity won't be tested

Redefined in descendants as:
getMemoryCachingState (line 500)

Load the state of the caching memory array from a given cache file cache

  • access: public
void getMemoryCachingState (string $id, [string $group = 'default'], [boolean $doNotTestCacheValidity = false])
  • string $id: cache id
  • string $group: name of the cache group
  • boolean $doNotTestCacheValidity: if set to true, the cache validity won't be tested
lastModified (line 518)

Return the cache last modification time

BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !

  • return: last modification time
int lastModified ()
raiseError (line 534)

Trigger a PEAR error

To improve performances, the PEAR.php file is included dynamically. The file is so included only when an error is triggered. So, in most cases, the file isn't included and perfs are much better.

  • access: public
void raiseError (string $msg, int $code)
  • string $msg: error message
  • int $code: error code
remove (line 416)

Remove a cache file

  • return: true if no problem
  • access: public
boolean remove (string $id, [string $group = 'default'])
  • string $id: cache id
  • string $group: name of the cache group
save (line 363)

Save some data in a cache file

  • return: true if no problem (else : false or a PEAR_Error object)
  • access: public
boolean save (string $data, [string $id = NULL], [string $group = 'default'])
  • string $data: data to put in cache (can be another type than strings if automaticSerialization is on)
  • string $id: cache id
  • string $group: name of the cache group
saveMemoryCachingState (line 480)

Save the state of the caching memory array into a cache file cache

  • access: public
void saveMemoryCachingState (string $id, [string $group = 'default'])
  • string $id: cache id
  • string $group: name of the cache group
setLifeTime (line 467)

Set a new life time

  • access: public
void setLifeTime (int $newLifeTime)
  • int $newLifeTime: new life time (in seconds)
setOption (line 296)

Generic way to set a Cache_Lite option

see Cache_Lite constructor for available options

  • var: name of the option
  • access: public
void setOption ( $name,  $value)
  • $name
  • $value
setToDebug (line 456)

Set to debug mode

When an error is found, the script will stop and the message will be displayed (in debug mode only).

  • access: public
void setToDebug ()

Documentation generated on Mon, 05 Mar 2007 21:09:50 +0000 by phpDocumentor 1.3.1