PHP 클래스 Cache_Lite, cachearium

파일 보기 프로젝트 열기: corollarium/cachearium 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$_automaticCleaningFactor integer The automatic cleaning process destroy too old (for the given life time) cache files when a new cache file is written. 0 => no automatic cache cleaning 1 => systematic cache cleaning x (integer) > 1 => automatic cleaning randomly 1 times on x cache write
$_automaticSerialization boolean it can be used to save directly datas which aren't strings (but it's slower)
$_cacheDir string Directory where to put the cache files (make sure to add a trailing slash)
$_caching boolean (can be very usefull for the debug of cached scripts)
$_errorHandlingAPIBreak boolean 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.
$_file string File name (with path)
$_fileLocking boolean (can avoid cache corruption under bad circumstances)
$_fileName string File name (without path)
$_fileNameProtection boolean 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...
$_group string Current cache group
$_hashedDirectoryLevel integer 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.
$_hashedDirectoryUmask integer Umask for hashed directory structure
$_id string Current cache id
$_lifeTime integer If null, the cache is valid forever.
$_memoryCaching boolean NB : There is no lifetime for memory caching !
$_memoryCachingArray array Memory caching array
$_memoryCachingCounter integer Memory caching counter
$_memoryCachingLimit integer Memory caching limit
$_onlyMemoryCaching boolean Enable / Disable "Only Memory Caching" (be carefull, memory caching is "beta quality")
$_pearErrorMode integer (see PEAR doc)
$_readControl boolean If enabled, a control key is embeded in cache file and this key is compared with the one calculated after the reading.
$_readControlType boolean 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)
$_refreshTime integer Timestamp of the last valid cache
$_writeControl boolean 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

공개 메소드들

메소드 설명
__construct ( array $options = [NULL] ) Constructor
_cleanDir ( string $dir, string $group = false, string $mode = 'ingroup' ) : boolean Recursive function for cleaning cache file in the given directory
_hash ( string $data, string $controlType ) : string Make a control key with the string containing datas
_memoryCacheAdd ( string $data ) Add some date in the memory caching array
_read ( ) : string Read the cache file and return the content
_setFileName ( string $id, string $group ) Make a file name (with path)
_setRefreshTime ( ) Compute & set the refresh time
_unlink ( string $file ) : boolean Remove a file
_write ( string $data ) : boolean Write the given data in the cache file
_writeAndControl ( string $data ) : boolean Write the given data in the cache file and control it just after to avoir corrupted cache entries
clean ( string $group = false, string $mode = 'ingroup' ) : boolean Clean the cache
extendLife ( ) Extend the life of a valid cache file
get ( string $id, string $group = 'default', boolean $doNotTestCacheValidity = false ) : string Test if a cache is available and (if yes) return it
getMemoryCachingState ( string $id, string $group = 'default', boolean $doNotTestCacheValidity = false ) Load the state of the caching memory array from a given cache file cache
lastModified ( ) : integer Return the cache last modification time
raiseError ( string $msg, integer $code ) Trigger error
remove ( string $id, string $group = 'default' ) : boolean Remove a cache file
save ( string $data, string $id = NULL, string $group = 'default' ) : boolean Save some data in a cache file
saveMemoryCachingState ( string $id, string $group = 'default' ) Save the state of the caching memory array into a cache file cache
setLifeTime ( integer $newLifeTime ) Set a new life time
setOption ( $name, $value ) Generic way to set a Cache_Lite option
setToDebug ( ) Set to debug mode

메소드 상세

__construct() 공개 메소드

$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) );
public __construct ( array $options = [NULL] )
$options array options

_cleanDir() 공개 메소드

Recursive function for cleaning cache file in the given directory
public _cleanDir ( string $dir, string $group = false, string $mode = 'ingroup' ) : boolean
$dir string directory complete path (with a trailing slash)
$group string name of the cache group
$mode string flush cache mode : 'old', 'ingroup', 'notingroup', 'callback_myFunction'
리턴 boolean true if no problem

_hash() 공개 메소드

Make a control key with the string containing datas
public _hash ( string $data, string $controlType ) : string
$data string data
$controlType string type of control 'md5', 'crc32' or 'strlen'
리턴 string control key

_memoryCacheAdd() 공개 메소드

Add some date in the memory caching array
public _memoryCacheAdd ( string $data )
$data string data to cache

_read() 공개 메소드

Read the cache file and return the content
public _read ( ) : string
리턴 string content of the cache file (else : false or a PEAR_Error object)

_setFileName() 공개 메소드

Make a file name (with path)
public _setFileName ( string $id, string $group )
$id string cache id
$group string name of the group

_setRefreshTime() 공개 메소드

Compute & set the refresh time
public _setRefreshTime ( )

_write() 공개 메소드

Write the given data in the cache file
public _write ( string $data ) : boolean
$data string data to put in cache
리턴 boolean true if ok (a PEAR_Error object else)

_writeAndControl() 공개 메소드

Write the given data in the cache file and control it just after to avoir corrupted cache entries
public _writeAndControl ( string $data ) : boolean
$data string data to put in cache
리턴 boolean true if the test is ok (else : false or a PEAR_Error object)

clean() 공개 메소드

if no group is specified all cache files will be destroyed else only cache files of the specified group will be destroyed
public clean ( string $group = false, string $mode = 'ingroup' ) : boolean
$group string name of the cache group
$mode string flush cache mode : 'old', 'ingroup', 'notingroup', 'callback_myFunction'
리턴 boolean true if no problem

extendLife() 공개 메소드

see http://pear.php.net/bugs/bug.php?id=6681
public extendLife ( )

get() 공개 메소드

Test if a cache is available and (if yes) return it
public get ( string $id, string $group = 'default', boolean $doNotTestCacheValidity = false ) : string
$id string cache id
$group string name of the cache group
$doNotTestCacheValidity boolean if set to true, the cache validity won't be tested
리턴 string data of the cache (else : false)

getMemoryCachingState() 공개 메소드

Load the state of the caching memory array from a given cache file cache
public getMemoryCachingState ( string $id, string $group = 'default', boolean $doNotTestCacheValidity = false )
$id string cache id
$group string name of the cache group
$doNotTestCacheValidity boolean if set to true, the cache validity won't be tested

lastModified() 공개 메소드

BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
public lastModified ( ) : integer
리턴 integer last modification time

raiseError() 공개 메소드

Trigger error
public raiseError ( string $msg, integer $code )
$msg string error message
$code integer error code

remove() 공개 메소드

Remove a cache file
public remove ( string $id, string $group = 'default' ) : boolean
$id string cache id
$group string name of the cache group
리턴 boolean true if no problem

save() 공개 메소드

Save some data in a cache file
public save ( string $data, string $id = NULL, string $group = 'default' ) : boolean
$data string data to put in cache (can be another type than strings if automaticSerialization is on)
$id string cache id
$group string name of the cache group
리턴 boolean true if no problem (else : false or a PEAR_Error object)

saveMemoryCachingState() 공개 메소드

Save the state of the caching memory array into a cache file cache
public saveMemoryCachingState ( string $id, string $group = 'default' )
$id string cache id
$group string name of the cache group

setLifeTime() 공개 메소드

Set a new life time
public setLifeTime ( integer $newLifeTime )
$newLifeTime integer new life time (in seconds)

setOption() 공개 메소드

see Cache_Lite constructor for available options
public setOption ( $name, $value )

setToDebug() 공개 메소드

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

프로퍼티 상세

$_automaticCleaningFactor 공개적으로 프로퍼티

The automatic cleaning process destroy too old (for the given life time) cache files when a new cache file is written. 0 => no automatic cache cleaning 1 => systematic cache cleaning x (integer) > 1 => automatic cleaning randomly 1 times on x cache write
public int $_automaticCleaningFactor
리턴 integer

$_automaticSerialization 공개적으로 프로퍼티

it can be used to save directly datas which aren't strings (but it's slower)
public bool $_automaticSerialization
리턴 boolean

$_cacheDir 공개적으로 프로퍼티

Directory where to put the cache files (make sure to add a trailing slash)
public string $_cacheDir
리턴 string

$_caching 공개적으로 프로퍼티

(can be very usefull for the debug of cached scripts)
public bool $_caching
리턴 boolean

$_errorHandlingAPIBreak 공개적으로 프로퍼티

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.
public bool $_errorHandlingAPIBreak
리턴 boolean

$_file 공개적으로 프로퍼티

File name (with path)
public string $_file
리턴 string

$_fileLocking 공개적으로 프로퍼티

(can avoid cache corruption under bad circumstances)
public bool $_fileLocking
리턴 boolean

$_fileName 공개적으로 프로퍼티

File name (without path)
public string $_fileName
리턴 string

$_fileNameProtection 공개적으로 프로퍼티

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...
public bool $_fileNameProtection
리턴 boolean

$_group 공개적으로 프로퍼티

Current cache group
public string $_group
리턴 string

$_hashedDirectoryLevel 공개적으로 프로퍼티

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.
public int $_hashedDirectoryLevel
리턴 integer

$_hashedDirectoryUmask 공개적으로 프로퍼티

Umask for hashed directory structure
public int $_hashedDirectoryUmask
리턴 integer

$_id 공개적으로 프로퍼티

Current cache id
public string $_id
리턴 string

$_lifeTime 공개적으로 프로퍼티

If null, the cache is valid forever.
public int $_lifeTime
리턴 integer

$_memoryCaching 공개적으로 프로퍼티

NB : There is no lifetime for memory caching !
public bool $_memoryCaching
리턴 boolean

$_memoryCachingArray 공개적으로 프로퍼티

Memory caching array
public array $_memoryCachingArray
리턴 array

$_memoryCachingCounter 공개적으로 프로퍼티

Memory caching counter
public int $_memoryCachingCounter
리턴 integer

$_memoryCachingLimit 공개적으로 프로퍼티

Memory caching limit
public int $_memoryCachingLimit
리턴 integer

$_onlyMemoryCaching 공개적으로 프로퍼티

Enable / Disable "Only Memory Caching" (be carefull, memory caching is "beta quality")
public bool $_onlyMemoryCaching
리턴 boolean

$_pearErrorMode 공개적으로 프로퍼티

(see PEAR doc)
또한 보기: setToDebug()
public int $_pearErrorMode
리턴 integer

$_readControl 공개적으로 프로퍼티

If enabled, a control key is embeded in cache file and this key is compared with the one calculated after the reading.
public bool $_readControl
리턴 boolean

$_readControlType 공개적으로 프로퍼티

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)
public bool $_readControlType
리턴 boolean

$_refreshTime 공개적으로 프로퍼티

Timestamp of the last valid cache
public int $_refreshTime
리턴 integer

$_writeControl 공개적으로 프로퍼티

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
public bool $_writeControl
리턴 boolean