phpDocumentor Cache_Lite
[ class tree: Cache_Lite ] [ index: Cache_Lite ] [ all elements ]

Class: Cache_Lite

Source Location: /lodel/scripts/Cache/Lite.php

Class Cache_Lite

Property Summary
int   $_automaticCleaningFactor   Disable / Tune the automatic cleaning process
boolean   $_automaticSerialization   Enable / disable automatic serialization
string   $_cacheDir   Directory where to put the cache files (make sure to add a trailing slash)
boolean   $_caching   Enable / disable caching
boolean   $_errorHandlingAPIBreak   API break for error handling in CACHE_LITE_ERROR_RETURN mode
string   $_file   File name (with path)
boolean   $_fileLocking   Enable / disable fileLocking
string   $_fileName   File name (without path)
boolean   $_fileNameProtection   File Name protection
string   $_group   Current cache group
int   $_hashedDirectoryLevel   Nested directory level
int   $_hashedDirectoryUmask   Umask for hashed directory structure
string   $_id   Current cache id
int   $_lifeTime   Cache lifetime (in seconds)
boolean   $_memoryCaching   Enable / Disable "Memory Caching"
array   $_memoryCachingArray   Memory caching array
int   $_memoryCachingCounter   Memory caching counter
int   $_memoryCachingLimit   Memory caching limit
boolean   $_onlyMemoryCaching   Enable / Disable "Only Memory Caching" (be carefull, memory caching is "beta quality")
int   $_pearErrorMode   Pear error mode (when raiseError is called)
boolean   $_readControl   Enable / disable read control
boolean   $_readControlType   Type of read control (only if read control is enabled)
int   $_refreshTime   Timestamp of the last valid cache
boolean   $_writeControl   Enable / disable write control (the cache is read just after writing to detect corrupt entries)

[ Top ]
Method Summary
Cache_Lite   Cache_Lite()   Constructor
boolean   clean()   Clean the cache
void   extendLife()   Extend the life of a valid cache file
string   get()   Test if a cache is available and (if yes) return it
void   getMemoryCachingState()   Load the state of the caching memory array from a given cache file cache
int   lastModified()   Return the cache last modification time
void   raiseError()   Trigger a PEAR error
boolean   remove()   Remove a cache file
boolean   save()   Save some data in a cache file
void   saveMemoryCachingState()   Save the state of the caching memory array into a cache file cache
void   setLifeTime()   Set a new life time
void   setOption()   Generic way to set a Cache_Lite option
void   setToDebug()   Set to debug mode
boolean   _cleanDir()   Recursive function for cleaning cache file in the given directory
string   _hash()   Make a control key with the string containing datas
void   _memoryCacheAdd()   Add some date in the memory caching array
string   _read()   Read the cache file and return the content
void   _setFileName()   Make a file name (with path)
void   _setRefreshTime()   Compute & set the refresh time
boolean   _unlink()   Remove a file
boolean   _write()   Write the given data in the cache file
boolean   _writeAndControl()   Write the given data in the cache file and control it just after to avoir corrupted cache entries

[ Top ]
Properties
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


[ Top ]
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)


[ Top ]
string   $_cacheDir = '/tmp/' [line 40]

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


[ Top ]
boolean   $_caching = true [line 49]

Enable / disable caching

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


[ Top ]
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.


[ Top ]
string   $_file [line 81]

File name (with path)


[ Top ]
boolean   $_fileLocking = true [line 67]

Enable / disable fileLocking

(can avoid cache corruption under bad circumstances)


[ Top ]
string   $_fileName [line 88]

File name (without path)


[ Top ]
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...


[ Top ]
string   $_group [line 144]

Current cache group


[ Top ]
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.


[ Top ]
int   $_hashedDirectoryUmask = 0700 [line 237]

Umask for hashed directory structure


[ Top ]
string   $_id [line 137]

Current cache id


[ Top ]
int   $_lifeTime = 3600 [line 58]

Cache lifetime (in seconds)

If null, the cache is valid forever.


[ Top ]
boolean   $_memoryCaching = false [line 153]

Enable / Disable "Memory Caching"

NB : There is no lifetime for memory caching !


[ Top ]
array   $_memoryCachingArray = array() [line 168]

Memory caching array


[ Top ]
int   $_memoryCachingCounter = 0 [line 175]

Memory caching counter


[ Top ]
int   $_memoryCachingLimit = 1000 [line 182]

Memory caching limit


[ Top ]
boolean   $_onlyMemoryCaching = false [line 161]

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


[ Top ]
int   $_pearErrorMode = CACHE_LITE_ERROR_RETURN [line 130]

Pear error mode (when raiseError is called)

(see PEAR doc)

API Tags:
See:  Cache_Lite::setToDebug()


[ Top ]
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.


[ Top ]
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)


[ Top ]
int   $_refreshTime [line 74]

Timestamp of the last valid cache


[ Top ]
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


[ Top ]
Methods
Constructor Cache_Lite  [line 280]

  Cache_Lite Cache_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' (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) );

Parameters:
array   $options:  options

API Tags:
Access:  public


[ Top ]
clean  [line 447]

  boolean clean( [string $group = false], [string $mode = 'ingroup']  )

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

Parameters:
string   $group:  name of the cache group
string   $mode:  flush cache mode : 'old', 'ingroup', 'notingroup', 'callback_myFunction'

API Tags:
Return:  true if no problem
Access:  public


[ Top ]
extendLife  [line 551]

  void extendLife( )

Extend the life of a valid cache file

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


API Tags:
Access:  public


[ Top ]
get  [line 314]

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

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

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

API Tags:
Return:  data of the cache (else : false)
Access:  public


Redefined in descendants as:

[ Top ]
getMemoryCachingState  [line 504]

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

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

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

API Tags:
Access:  public


[ Top ]
lastModified  [line 522]

  int lastModified( )

Return the cache last modification time

BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !


API Tags:
Return:  last modification time


[ Top ]
raiseError  [line 538]

  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.

Parameters:
string   $msg:  error message
int   $code:  error code

API Tags:
Access:  public


[ Top ]
remove  [line 417]

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

Remove a cache file

Parameters:
string   $id:  cache id
string   $group:  name of the cache group
boolean   $checkbeforeunlink:  check if file exists before removing it

API Tags:
Return:  true if no problem
Access:  public


[ Top ]
save  [line 363]

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

Save some data in a cache file

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

API Tags:
Return:  true if no problem (else : false or a PEAR_Error object)
Access:  public


[ Top ]
saveMemoryCachingState  [line 484]

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

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

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

API Tags:
Access:  public


[ Top ]
setLifeTime  [line 471]

  void setLifeTime( int $newLifeTime  )

Set a new life time

Parameters:
int   $newLifeTime:  new life time (in seconds)

API Tags:
Access:  public


[ Top ]
setOption  [line 296]

  void setOption( $name, $value  )

Generic way to set a Cache_Lite option

see Cache_Lite constructor for available options

Parameters:
   $name: 
   $value: 

API Tags:
Access:  public


[ Top ]
setToDebug  [line 460]

  void setToDebug( )

Set to debug mode

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


API Tags:
Access:  public


[ Top ]
_cleanDir  [line 597]

  boolean _cleanDir( string $dir, [string $group = false], [string $mode = 'ingroup']  )

Recursive function for cleaning cache file in the given directory

Parameters:
string   $dir:  directory complete path (with a trailing slash)
string   $group:  name of the cache group
string   $mode:  flush cache mode : 'old', 'ingroup', 'notingroup',

API Tags:
Return:  true if no problem
Access:  private


[ Top ]
_hash  [line 814]

  string _hash( string $data, string $controlType  )

Make a control key with the string containing datas

Parameters:
string   $data:  data
string   $controlType:  type of control 'md5', 'crc32' or 'strlen'

API Tags:
Return:  control key
Access:  private


[ Top ]
_memoryCacheAdd  [line 667]

  void _memoryCacheAdd( string $data  )

Add some date in the memory caching array

Parameters:
string   $data:  data to cache

API Tags:
Access:  private


[ Top ]
_read  [line 710]

  string _read( )

Read the cache file and return the content


API Tags:
Return:  content of the cache file (else : false or a PEAR_Error object)
Access:  private


[ Top ]
_setFileName  [line 685]

  void _setFileName( string $id, string $group  )

Make a file name (with path)

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

API Tags:
Access:  private


[ Top ]
_setRefreshTime  [line 563]

  void _setRefreshTime( )

Compute & set the refresh time


API Tags:
Access:  private


[ Top ]
_unlink  [line 579]

  boolean _unlink( string $file  )

Remove a file

Parameters:
string   $file:  complete file path and name

API Tags:
Return:  true if no problem
Access:  private


[ Top ]
_write  [line 754]

  boolean _write( string $data  )

Write the given data in the cache file

Parameters:
string   $data:  data to put in cache

API Tags:
Return:  true if ok (a PEAR_Error object else)
Access:  private


[ Top ]
_writeAndControl  [line 790]

  boolean _writeAndControl( string $data  )

Write the given data in the cache file and control it just after to avoir corrupted cache entries

Parameters:
string   $data:  data to put in cache

API Tags:
Return:  true if the test is ok (else : false or a PEAR_Error object)
Access:  private


[ Top ]

Documentation generated on Thu, 19 Jun 2008 05:08:02 +0200 by phpDocumentor 1.4.0a2