Class TCache_Lite

Description

Fast, light and safe Cache Class

TCache_Lite is a fast, light and safe cache system. It's optimized for file containers. It is fast and safe (because it uses file locking and/or anti-corruption tests).

There are some examples in the 'docs/examples' file Technical choices are described in the 'docs/technical' file

A tutorial is available in english at this url : http://www.pearfr.org/index.php/en/article/cache_lite (big thanks to Pierre-Alain Joye for the translation)

The same tutorial is also available in french at this url : http://www.pearfr.org/index.php/fr/article/cache_lite

Memory Caching is from an original idea of Mike BENOIT <ipso@snappymail.ca>

Located in /I18N/core/TCache_Lite.php (line 47)


	
			
Variable Summary
Method Summary
TCache_Lite TCache_Lite ([array $options = array(null)])
boolean clean ([string $group = false])
string get (string $id, [string $group = 'default'], [boolean $doNotTestCacheValidity = false])
void getCacheFile ()
void getMemoryCachingState (mixed $id, [mixed $group = 'default'], [mixed $doNotTestCacheValidity = false])
int lastModified ()
void raiseError (string $msg, int $code)
boolean remove (string $id, [string $group = 'default'])
boolean save (string $data, [string $id = null], [string $group = 'default'])
void saveMemoryCachingState (mixed $id, [mixed $group = 'default'])
void setLifeTime (int $newLifeTime)
Variables
boolean $_automaticSerialization = false (line 206)

Enable / disable automatic serialization

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

  • access: protected
string $_cacheDir = '/tmp/' (line 58)

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

  • access: protected
boolean $_caching = true (line 67)

Enable / disable caching

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

  • access: protected
string $_file (line 97)

File name (with path)

  • access: protected
boolean $_fileLocking = true (line 83)

Enable / disable fileLocking

(can avoid cache corruption under bad circumstances)

  • access: protected
boolean $_fileNameProtection = true (line 196)

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...

  • access: protected
string $_group (line 146)

Current cache group

  • access: protected
string $_id (line 139)

Current cache id

  • access: protected
int $_lifeTime = 3600 (line 74)

Cache lifetime (in seconds)

  • access: protected
boolean $_memoryCaching = false (line 155)

Enable / Disable "Memory Caching"

NB : There is no lifetime for memory caching !

  • access: protected
array $_memoryCachingArray = array() (line 170)

Memory caching array

  • access: protected
int $_memoryCachingCounter = 0 (line 177)

Memory caching counter

  • access: protected
int $_memoryCachingLimit = 1000 (line 184)

Memory caching limit

  • access: protected
boolean $_onlyMemoryCaching = false (line 163)

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

  • access: protected
boolean $_readControl = true (line 119)

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.

  • access: protected
boolean $_readControlType = 'crc32' (line 132)

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)

  • access: protected
int $_refreshTime (line 90)

Timestamp of the last valid cache

  • access: protected
boolean $_writeControl = true (line 109)

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

  • access: protected
Methods
Constructor TCache_Lite (line 232)

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', 'memoryCaching' => enable / disable memory caching (boolean), 'onlyMemoryCaching' => enable / disable only memory caching (boolean), 'memoryCachingLimit' => max nbr of records in memory caching (int), 'fileNameProtection' => enable / disable file name protection (boolean), 'automaticSerialization' => enable / disable serialization (boolean) );

  • access: public
TCache_Lite TCache_Lite ([array $options = array(null)])
  • array $options: options
clean (line 373)

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 $group: name of the cache group
get (line 265)

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

  • return: data of the cache (or false if no cache available)
  • 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
getCacheFile (line 518)
void getCacheFile ()
getMemoryCachingState (line 444)
  • access: public
void getMemoryCachingState (mixed $id, [mixed $group = 'default'], [mixed $doNotTestCacheValidity = false])
lastModified (line 464)

Return the cache last modification time

BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !

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

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 353)

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 316)

Save some data in a cache file

  • return: true if no problem
  • 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 428)
  • access: public
void saveMemoryCachingState (mixed $id, [mixed $group = 'default'])
setLifeTime (line 418)

Set a new life time

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

Documentation generated on Sun, 04 Jun 2006 18:58:43 -0400 by phpDocumentor 1.3.0RC4