PHP Класс Cachearium\CacheAbstract

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$debugLogFile Controls debug to a file
$debugOnPage boolean Controls debug on html page for all Cache backends.

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

Свойство Тип Описание
$cache_log array Stores cache log for debugging.
$enabled boolean Is this cache enabled?
$lifetime
$namespace string Initialize it to a unique string. If you are not running multiple instances, ignore.
$should_log boolean Is log enabled? Log can take a lot of RAM, so only turn this on when profiling.
$summary array Array for basic cache profiling. Keys are CacheLogEnum, values are counters.

Открытые методы

Метод Описание
appendCallback ( callable $callback ) : boolean Appends a callback to the current start()/end() cache
clean ( CacheKey $k ) : boolean Cleans cache: all entries with a certain $base and $id in the $key are deleted.
cleanP ( $base, $id ) : boolean Cleans cache: all entries with a certain $base and $id
clear ( ) Clears entire cache. Use sparingly.
clearAll ( ) Clears all cache classes.
cssDebug ( ) Renders CSS for live view debugging of cached data.
delete ( CacheKey $k ) : boolean Deletes an entry from the cache
deleteP ( string $base, string $id, mixed $sub = null )
disable ( ) : CacheAbstract Disable this cache
dumpSummary ( ) Dumps a short HTML summary of the cache hits/misses
enable ( ) : CacheAbstract Enable this cache
end ( $print = true ) Ends the cache start().
factory ( string $backend ) : CacheAbstract Returns a cache
footerDebug ( ) Extensive footer debug code. Shows which parts of the HTML were cached or missed visually. Great!
get ( CacheKey $k ) : mixed Get cached entry.
getData ( CacheKey $k ) : CacheData Same as get, but assumes data was stored with a CacheData object and will treat it accordingly.
getDataP ( string $base, string $id, mixed $sub = null ) Same as getData(), but expanded parameters.
getDefaultLifetime ( )
getLogSummary ( ) : array() Returns basic cache statistics. See $summary.
getMulti ( array $cacheid, callable $callback = null ) : array:mixed Gets data from multiple cache keys at once
getNamespace ( ) : string
getP ( string $base, string $id, mixed $sub = null ) : mixed Same as get(), but expanded parameters.
increment ( integer $value, CacheKey $k, integer $default ) : integer Increment a variable. Backend deals with this, but in general this is atomic.
invalidate ( CacheKey $k ) Invalidates a dependency index. If the index does not exist it is created.
isEnabled ( ) : True
logHigh ( $message ) High level log for testing and debugging
newEnd ( $print = true )
newstart ( CacheKey $k, $lifetime = null, $fail = false )
prefetch ( array $data ) Prefetches data which will be used. This avoids multiple trips to the cache server if they can be avoided.
recursiveEnd ( boolean $print = true ) : string
recursiveStart ( CacheKey $k, integer $lifetime = null, boolean $print = true, boolean $fail = false ) : string
recursiveStartP ( $base, $id, $sub = null, $lifetime = null, $print = true, $fail = false )
report ( ) Generates a report for this backend
resetLogSummary ( )
setDefaultLifetime ( number $lifetime )
setEnabled ( $b ) : CacheAbstract Enable this cache
setLog ( boolean $b ) : CacheAbstract
setNamespace ( string $name )
start ( CacheKey $k, string $lifetime = null, boolean $print = true, boolean $fail = false ) : boolean | string Starts a cache if it doesn't exist, or outputs the data and returns true.
startCallback ( CacheKey $k, callable $c, array $cparams = [], integer $lifetime = null ) start() using a callable. Same as start()/c()/end().
startP ( $base, $id, $sub = null, $lifetime = null, $print = true, $fail = false )
store ( mixed $data, CacheKey $k, integer $lifetime ) : boolean Saves data in cache.
storeData ( CacheData $data, number $lifetime ) : boolean Same as store() but expanded parameters
storeP ( mixed $data, string $base, string $id, string $sub = null, number $lifetime ) : boolean Same as store() but expanded parameters

Защищенные методы

Метод Описание
hashKey ( CacheKey $k ) Returns a key given parameters. This is up to storage and different values may be returned for the same parameters, as storages are likely to use key-based cache expiration.
keyFromDeps ( CacheKey $k, $deps )
log ( string $status, CacheKey $k, integer $lifetime ) Logs cache accesses for debugging
printProbeEnd ( string $key, CacheData $cachedata ) Prints HTML for cache debug probes -> closes tag
printProbeStart ( string $key, CacheData $cachedata, string $type ) Prints HTML for cache debug probes -> opens tag

Приватные методы

Метод Описание
extraSub ( unknown &$sub ) Get extra sub

Описание методов

appendCallback() публичный Метод

Callbacks are always called at runtime, their result is never cached at this level. You may cache it in the callback, of course.
public appendCallback ( callable $callback ) : boolean
$callback callable
Результат boolean

clean() публичный Метод

Cleans cache: all entries with a certain $base and $id in the $key are deleted.
public clean ( CacheKey $k ) : boolean
$k CacheKey
Результат boolean true if no problem

cleanP() абстрактный публичный Метод

Cleans cache: all entries with a certain $base and $id
abstract public cleanP ( $base, $id ) : boolean
Результат boolean true if no problem

clear() абстрактный публичный Метод

Clears entire cache. Use sparingly.
abstract public clear ( )

clearAll() публичный статический Метод

Clears all cache classes.
public static clearAll ( )

cssDebug() публичный статический Метод

Renders CSS for live view debugging of cached data.
public static cssDebug ( )

delete() абстрактный публичный Метод

Deletes an entry from the cache
abstract public delete ( CacheKey $k ) : boolean
$k CacheKey
Результат boolean

deleteP() публичный Метод

См. также: delete()
public deleteP ( string $base, string $id, mixed $sub = null )
$base string
$id string
$sub mixed

disable() публичный Метод

Disable this cache
public disable ( ) : CacheAbstract
Результат CacheAbstract

dumpSummary() публичный статический Метод

Dumps a short HTML summary of the cache hits/misses
public static dumpSummary ( )

enable() публичный Метод

Enable this cache
public enable ( ) : CacheAbstract
Результат CacheAbstract this

end() публичный Метод

Ends the cache start().
См. также: recursiveEnd()
public end ( $print = true )

factory() публичный статический Метод

Returns a cache
public static factory ( string $backend ) : CacheAbstract
$backend string
Результат CacheAbstract

footerDebug() публичный статический Метод

Extensive footer debug code. Shows which parts of the HTML were cached or missed visually. Great!
public static footerDebug ( )

get() абстрактный публичный Метод

Get cached entry.
abstract public get ( CacheKey $k ) : mixed
$k CacheKey
Результат mixed

getData() публичный Метод

Same as get, but assumes data was stored with a CacheData object and will treat it accordingly.
public getData ( CacheKey $k ) : CacheData
$k CacheKey
Результат CacheData

getDataP() публичный Метод

Same as getData(), but expanded parameters.
См. также: getData()
public getDataP ( string $base, string $id, mixed $sub = null )
$base string
$id string
$sub mixed

getDefaultLifetime() публичный Метод

public getDefaultLifetime ( )

getLogSummary() публичный статический Метод

Returns basic cache statistics. See $summary.
public static getLogSummary ( ) : array()
Результат array()

getMulti() публичный Метод

Backends may override this to provide an efficient implementation over multiple calls to get().
public getMulti ( array $cacheid, callable $callback = null ) : array:mixed
$cacheid array List of cache keys
$callback callable if present will be called for any \NotCachedExceptions. Callback should have this signature: (CacheAbstract $c, CacheKey $k)
Результат array:mixed

getNamespace() публичный Метод

public getNamespace ( ) : string
Результат string

getP() публичный Метод

Same as get(), but expanded parameters.
См. также: getK
public getP ( string $base, string $id, mixed $sub = null ) : mixed
$base string
$id string
$sub mixed
Результат mixed

hashKey() абстрактный защищенный Метод

Returns a key given parameters. This is up to storage and different values may be returned for the same parameters, as storages are likely to use key-based cache expiration.
abstract protected hashKey ( CacheKey $k )
$k CacheKey

increment() абстрактный публичный Метод

Backend must only guarantee that the increment is made, but the final value may not be current + $value due to concurrent accesses.
abstract public increment ( integer $value, CacheKey $k, integer $default ) : integer
$value integer
$k CacheKey
$default integer If key is not in cache, this value is returned.
Результат integer

invalidate() публичный Метод

Invalidates a dependency index. If the index does not exist it is created.
public invalidate ( CacheKey $k )
$k CacheKey

isEnabled() публичный Метод

public isEnabled ( ) : True
Результат True if cache is enabled, working and storing/retrieving data.

keyFromDeps() защищенный Метод

protected keyFromDeps ( CacheKey $k, $deps )
$k CacheKey

log() защищенный Метод

Logs cache accesses for debugging
protected log ( string $status, CacheKey $k, integer $lifetime )
$status string CacheLogEnum constant
$k CacheKey The message to print.
$lifetime integer

logHigh() публичный статический Метод

High level log for testing and debugging
public static logHigh ( $message )

newEnd() публичный Метод

public newEnd ( $print = true )

newstart() публичный Метод

public newstart ( CacheKey $k, $lifetime = null, $fail = false )
$k CacheKey

prefetch() абстрактный публичный Метод

Backend may ignore this call and implement a noop.
abstract public prefetch ( array $data )
$data array array(0 => CacheKey, ...)

printProbeEnd() защищенный Метод

Prints HTML for cache debug probes -> closes tag
protected printProbeEnd ( string $key, CacheData $cachedata )
$key string
$cachedata CacheData

printProbeStart() защищенный Метод

Prints HTML for cache debug probes -> opens tag
protected printProbeStart ( string $key, CacheData $cachedata, string $type )
$key string
$cachedata CacheData
$type string

recursiveEnd() публичный Метод

public recursiveEnd ( boolean $print = true ) : string
$print boolean
Результат string The string. If $print == true the string is printed as well.

recursiveStart() публичный Метод

public recursiveStart ( CacheKey $k, integer $lifetime = null, boolean $print = true, boolean $fail = false ) : string
$k CacheKey
$lifetime integer if null uses the class default
$print boolean
$fail boolean if true throws a NotCachedException if not cached.
Результат string The cached item as a string or false if not cached.

recursiveStartP() публичный Метод

См. также: recursiveStart()
public recursiveStartP ( $base, $id, $sub = null, $lifetime = null, $print = true, $fail = false )

report() абстрактный публичный Метод

Generates a report for this backend
abstract public report ( )

resetLogSummary() публичный статический Метод

public static resetLogSummary ( )

setDefaultLifetime() публичный Метод

public setDefaultLifetime ( number $lifetime )
$lifetime number 0 for infinite

setEnabled() закрытый публичный Метод

Enable this cache
final public setEnabled ( $b ) : CacheAbstract
Результат CacheAbstract this

setLog() публичный Метод

public setLog ( boolean $b ) : CacheAbstract
$b boolean
Результат CacheAbstract

setNamespace() публичный Метод

public setNamespace ( string $name )
$name string An optional namespace.

start() публичный Метод

Calls extraSub().
public start ( CacheKey $k, string $lifetime = null, boolean $print = true, boolean $fail = false ) : boolean | string
$k CacheKey
$lifetime string The lifetime, in seconds
$print boolean if True echoes the data
$fail boolean if false throws an exception if something happens, such as not cached
Результат boolean | string True if cached

startCallback() публичный Метод

start() using a callable. Same as start()/c()/end().
public startCallback ( CacheKey $k, callable $c, array $cparams = [], integer $lifetime = null )
$k CacheKey
$c callable A callable. Whatever it prints will be cached.
$cparams array parameters for the callback, optional
$lifetime integer

startP() публичный Метод

См. также: start()
public startP ( $base, $id, $sub = null, $lifetime = null, $print = true, $fail = false )

store() абстрактный публичный Метод

Saves data in cache.
abstract public store ( mixed $data, CacheKey $k, integer $lifetime ) : boolean
$data mixed Data to save in cache
$k CacheKey
$lifetime integer The lifetime in sceonds, although it is up to the implementation whether it is respected or not.
Результат boolean true if no problem

storeData() публичный Метод

Same as store() but expanded parameters
См. также: store()
public storeData ( CacheData $data, number $lifetime ) : boolean
$data CacheData
$lifetime number
Результат boolean true if no problem

storeP() публичный Метод

Same as store() but expanded parameters
См. также: store()
public storeP ( mixed $data, string $base, string $id, string $sub = null, number $lifetime ) : boolean
$data mixed
$base string
$id string
$sub string
$lifetime number
Результат boolean true if no problem

Описание свойств

$cache_log защищенное свойство

Stores cache log for debugging.
protected array $cache_log
Результат array

$debugLogFile публичное статическое свойство

Controls debug to a file
public static $debugLogFile

$debugOnPage публичное статическое свойство

Controls debug on html page for all Cache backends.
public static bool $debugOnPage
Результат boolean

$enabled защищенное свойство

Is this cache enabled?
protected bool $enabled
Результат boolean

$lifetime защищенное свойство

protected $lifetime

$namespace защищенное свойство

Initialize it to a unique string. If you are not running multiple instances, ignore.
protected string $namespace
Результат string

$should_log защищенное свойство

Is log enabled? Log can take a lot of RAM, so only turn this on when profiling.
protected bool $should_log
Результат boolean

$summary защищенное статическое свойство

Array for basic cache profiling. Keys are CacheLogEnum, values are counters.
protected static array $summary
Результат array