PHP 클래스 Prado\I18N\core\TCache_Lite

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
저자: Fabien MARTY ([email protected])
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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)
$_file string File name (with path)
$_fileLocking boolean (can avoid cache corruption under bad circumstances)
$_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
$_id string Current cache id
$_lifeTime integer Cache lifetime (in seconds)
$_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")
$_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
_hash ( string $data, string $controlType ) : string Make a control key with the string containing datas
_memoryCacheAdd ( $id, $data )
_read ( ) : string Read the cache file and return the content
_setFileName ( string $id, string $group ) Make a file name (with path)
_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 avoid corrupted cache entries
clean ( string $group = false ) : boolean Clean the cache
get ( string $id, string $group = 'default', boolean $doNotTestCacheValidity = false ) : string Test if a cache is available and (if yes) return it
getCacheFile ( )
getMemoryCachingState ( $id, $group = 'default', $doNotTestCacheValidity = false )
lastModified ( ) : integer Return the cache last modification time
raiseError ( string $msg, integer $code ) Trigger a PEAR 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 ( $id, $group = 'default' )
setLifeTime ( integer $newLifeTime ) Set a new life time

메소드 상세

__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', '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) );
public __construct ( array $options = [null] )
$options array options

_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() 공개 메소드

public _memoryCacheAdd ( $id, $data )

_read() 공개 메소드

Read the cache file and return the content
public _read ( ) : string
리턴 string content of the cache file

_setFileName() 공개 메소드

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

_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

_writeAndControl() 공개 메소드

Write the given data in the cache file and control it just after to avoid corrupted cache entries
public _writeAndControl ( string $data ) : boolean
$data string data to put in cache
리턴 boolean true if the test is ok

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 ) : boolean
$group string name of the cache group
리턴 boolean true if no problem

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 (or false if no cache available)

getCacheFile() 공개 메소드

public getCacheFile ( )

getMemoryCachingState() 공개 메소드

public getMemoryCachingState ( $id, $group = 'default', $doNotTestCacheValidity = false )

lastModified() 공개 메소드

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

raiseError() 공개 메소드

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

saveMemoryCachingState() 공개 메소드

public saveMemoryCachingState ( $id, $group = 'default' )

setLifeTime() 공개 메소드

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

프로퍼티 상세

$_automaticSerialization 보호되어 있는 프로퍼티

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

$_cacheDir 보호되어 있는 프로퍼티

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

$_caching 보호되어 있는 프로퍼티

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

$_file 보호되어 있는 프로퍼티

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

$_fileLocking 보호되어 있는 프로퍼티

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

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

$_group 보호되어 있는 프로퍼티

Current cache group
protected string $_group
리턴 string

$_id 보호되어 있는 프로퍼티

Current cache id
protected string $_id
리턴 string

$_lifeTime 보호되어 있는 프로퍼티

Cache lifetime (in seconds)
protected int $_lifeTime
리턴 integer

$_memoryCaching 보호되어 있는 프로퍼티

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

$_memoryCachingArray 보호되어 있는 프로퍼티

Memory caching array
protected array $_memoryCachingArray
리턴 array

$_memoryCachingCounter 보호되어 있는 프로퍼티

Memory caching counter
protected int $_memoryCachingCounter
리턴 integer

$_memoryCachingLimit 보호되어 있는 프로퍼티

Memory caching limit
protected int $_memoryCachingLimit
리턴 integer

$_onlyMemoryCaching 보호되어 있는 프로퍼티

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

$_readControl 보호되어 있는 프로퍼티

If enabled, a control key is embeded in cache file and this key is compared with the one calculated after the reading.
protected 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)
protected bool $_readControlType
리턴 boolean

$_refreshTime 보호되어 있는 프로퍼티

Timestamp of the last valid cache
protected 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
protected bool $_writeControl
리턴 boolean