System.I18N.core
[ class tree: System.I18N.core ] [ index: System.I18N.core ] [ all elements ]

Class: TCache_Lite

Source Location: /I18N/core/TCache_Lite.php

Class Overview


Fast, light and safe Cache Class

Class Details

[line 44]
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>




author:  Fabien MARTY <fab@php.net>
version:  $Id: TCache_Lite.php,v 1.3 2005/10/09 10:24:12 weizhuo Exp $


[ Top ]

Variables

Methods



Class Variables

$_automaticSerialization =  false

[line 203]

Enable / disable automatic serialization

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




access:  protected

Type:   boolean


[ Top ]

$_cacheDir =  '/tmp/'

[line 55]

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



access:  protected

Type:   string


[ Top ]

$_caching =  true

[line 64]

Enable / disable caching

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




access:  protected

Type:   boolean


[ Top ]

$_file =

[line 94]

File name (with path)



access:  protected

Type:   string


[ Top ]

$_fileLocking =  true

[line 80]

Enable / disable fileLocking

(can avoid cache corruption under bad circumstances)




access:  protected

Type:   boolean


[ Top ]

$_fileNameProtection =  true

[line 193]

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

Type:   boolean


[ Top ]

$_group =

[line 143]

Current cache group



access:  protected

Type:   string


[ Top ]

$_id =

[line 136]

Current cache id



access:  protected

Type:   string


[ Top ]

$_lifeTime =  3600

[line 71]

Cache lifetime (in seconds)



access:  protected

Type:   int


[ Top ]

$_memoryCaching =  false

[line 152]

Enable / Disable "Memory Caching"

NB : There is no lifetime for memory caching !




access:  protected

Type:   boolean


[ Top ]

$_memoryCachingArray = array()

[line 167]

Memory caching array



access:  protected

Type:   array


[ Top ]

$_memoryCachingCounter =  0

[line 174]

Memory caching counter



access:  protected

Type:   int


[ Top ]

$_memoryCachingLimit =  1000

[line 181]

Memory caching limit



access:  protected

Type:   int


[ Top ]

$_onlyMemoryCaching =  false

[line 160]

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



access:  protected

Type:   boolean


[ Top ]

$_readControl =  true

[line 116]

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

Type:   boolean


[ Top ]

$_readControlType =  'crc32'

[line 129]

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

Type:   boolean


[ Top ]

$_refreshTime =

[line 87]

Timestamp of the last valid cache



access:  protected

Type:   int


[ Top ]

$_writeControl =  true

[line 106]

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

Type:   boolean


[ Top ]



Class Methods


constructor TCache_Lite [line 229]

TCache_Lite TCache_Lite( [array $options = array(NULL)])

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


Parameters:

array   $options   options

[ Top ]

method clean [line 370]

boolean clean( [string $group = false])

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


Parameters:

string   $group   name of the cache group

[ Top ]

method get [line 262]

string get( string $id, [string $group = 'default'], [boolean $doNotTestCacheValidity = false])

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



return:  data of the cache (or false if no cache available)
access:  public


Parameters:

string   $id   cache id
string   $group   name of the cache group
boolean   $doNotTestCacheValidity   if set to true, the cache validity won't be tested

[ Top ]

method getCacheFile [line 515]

void getCacheFile( )



[ Top ]

method getMemoryCachingState [line 441]

void getMemoryCachingState( mixed $id, [mixed $group = 'default'], [mixed $doNotTestCacheValidity = false])



access:  public


[ Top ]

method lastModified [line 461]

int lastModified( )

Return the cache last modification time

BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !




return:  last modification time


[ Top ]

method raiseError [line 476]

void raiseError( string $msg, int $code)

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


Parameters:

string   $msg   error message
int   $code   error code

[ Top ]

method remove [line 350]

boolean remove( string $id, [string $group = 'default'])

Remove a cache file



return:  true if no problem
access:  public


Parameters:

string   $id   cache id
string   $group   name of the cache group

[ Top ]

method save [line 313]

boolean save( string $data, [string $id = NULL], [string $group = 'default'])

Save some data in a cache file



return:  true if no problem
access:  public


Parameters:

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

[ Top ]

method saveMemoryCachingState [line 425]

void saveMemoryCachingState( mixed $id, [mixed $group = 'default'])



access:  public


[ Top ]

method setLifeTime [line 415]

void setLifeTime( int $newLifeTime)

Set a new life time



access:  public


Parameters:

int   $newLifeTime   new life time (in seconds)

[ Top ]


© 2004-2005 PRADO Software Group. All Rights Reserved.