PHP Class Cachearium\CacheAbstract

Afficher le fichier Open project: corollarium/cachearium Class Usage Examples

Méthodes publiques

Свойство Type Description
$debugLogFile Controls debug to a file
$debugOnPage boolean Controls debug on html page for all Cache backends.

Protected Properties

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
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

Méthodes protégées

Méthode Description
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

Private Methods

Méthode Description
extraSub ( unknown &$sub ) Get extra sub

Method Details

appendCallback() public méthode

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
Résultat boolean

clean() public méthode

Cleans cache: all entries with a certain $base and $id in the $key are deleted.
public clean ( CacheKey $k ) : boolean
$k CacheKey
Résultat boolean true if no problem

cleanP() abstract public méthode

Cleans cache: all entries with a certain $base and $id
abstract public cleanP ( $base, $id ) : boolean
Résultat boolean true if no problem

clear() abstract public méthode

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

clearAll() public static méthode

Clears all cache classes.
public static clearAll ( )

cssDebug() public static méthode

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

delete() abstract public méthode

Deletes an entry from the cache
abstract public delete ( CacheKey $k ) : boolean
$k CacheKey
Résultat boolean

deleteP() public méthode

See also: delete()
public deleteP ( string $base, string $id, mixed $sub = null )
$base string
$id string
$sub mixed

disable() public méthode

Disable this cache
public disable ( ) : CacheAbstract
Résultat CacheAbstract

dumpSummary() public static méthode

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

enable() public méthode

Enable this cache
public enable ( ) : CacheAbstract
Résultat CacheAbstract this

end() public méthode

Ends the cache start().
See also: recursiveEnd()
public end ( $print = true )

factory() public static méthode

Returns a cache
public static factory ( string $backend ) : CacheAbstract
$backend string
Résultat CacheAbstract

footerDebug() public static méthode

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

get() abstract public méthode

Get cached entry.
abstract public get ( CacheKey $k ) : mixed
$k CacheKey
Résultat mixed

getData() public méthode

Same as get, but assumes data was stored with a CacheData object and will treat it accordingly.
public getData ( CacheKey $k ) : CacheData
$k CacheKey
Résultat CacheData

getDataP() public méthode

Same as getData(), but expanded parameters.
See also: getData()
public getDataP ( string $base, string $id, mixed $sub = null )
$base string
$id string
$sub mixed

getDefaultLifetime() public méthode

public getDefaultLifetime ( )

getLogSummary() public static méthode

Returns basic cache statistics. See $summary.
public static getLogSummary ( ) : array()
Résultat array()

getMulti() public méthode

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)
Résultat array:mixed

getNamespace() public méthode

public getNamespace ( ) : string
Résultat string

getP() public méthode

Same as get(), but expanded parameters.
See also: getK
public getP ( string $base, string $id, mixed $sub = null ) : mixed
$base string
$id string
$sub mixed
Résultat mixed

hashKey() abstract protected méthode

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() abstract public méthode

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.
Résultat integer

invalidate() public méthode

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

isEnabled() public méthode

public isEnabled ( ) : True
Résultat True if cache is enabled, working and storing/retrieving data.

keyFromDeps() protected méthode

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

log() protected méthode

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() public static méthode

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

newEnd() public méthode

public newEnd ( $print = true )

newstart() public méthode

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

prefetch() abstract public méthode

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

printProbeEnd() protected méthode

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

printProbeStart() protected méthode

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

recursiveEnd() public méthode

public recursiveEnd ( boolean $print = true ) : string
$print boolean
Résultat string The string. If $print == true the string is printed as well.

recursiveStart() public méthode

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.
Résultat string The cached item as a string or false if not cached.

recursiveStartP() public méthode

See also: recursiveStart()
public recursiveStartP ( $base, $id, $sub = null, $lifetime = null, $print = true, $fail = false )

report() abstract public méthode

Generates a report for this backend
abstract public report ( )

resetLogSummary() public static méthode

public static resetLogSummary ( )

setDefaultLifetime() public méthode

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

setEnabled() final public méthode

Enable this cache
final public setEnabled ( $b ) : CacheAbstract
Résultat CacheAbstract this

setLog() public méthode

public setLog ( boolean $b ) : CacheAbstract
$b boolean
Résultat CacheAbstract

setNamespace() public méthode

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

start() public méthode

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
Résultat boolean | string True if cached

startCallback() public méthode

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() public méthode

See also: start()
public startP ( $base, $id, $sub = null, $lifetime = null, $print = true, $fail = false )

store() abstract public méthode

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.
Résultat boolean true if no problem

storeData() public méthode

Same as store() but expanded parameters
See also: store()
public storeData ( CacheData $data, number $lifetime ) : boolean
$data CacheData
$lifetime number
Résultat boolean true if no problem

storeP() public méthode

Same as store() but expanded parameters
See also: 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
Résultat boolean true if no problem

Property Details

$cache_log protected_oe property

Stores cache log for debugging.
protected array $cache_log
Résultat array

$debugLogFile public_oe static_oe property

Controls debug to a file
public static $debugLogFile

$debugOnPage public_oe static_oe property

Controls debug on html page for all Cache backends.
public static bool $debugOnPage
Résultat boolean

$enabled protected_oe property

Is this cache enabled?
protected bool $enabled
Résultat boolean

$lifetime protected_oe property

protected $lifetime

$namespace protected_oe property

Initialize it to a unique string. If you are not running multiple instances, ignore.
protected string $namespace
Résultat string

$should_log protected_oe property

Is log enabled? Log can take a lot of RAM, so only turn this on when profiling.
protected bool $should_log
Résultat boolean

$summary protected_oe static_oe property

Array for basic cache profiling. Keys are CacheLogEnum, values are counters.
protected static array $summary
Résultat array