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])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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