\Smarty_CacheResource_KeyValueStore

Smarty Cache Handler Base for Key/Value Storage Implementations

This class implements the functionality required to use simple key/value stores for hierarchical cache groups. key/value stores like memcache or APC do not support wildcards in keys, therefore a cache group cannot be cleared like "a|*" - which is no problem to filesystem and RDBMS implementations.

This implementation is based on the concept of invalidation. While one specific cache can be identified and cleared, any range of caches cannot be identified. For this reason each level of the cache group hierarchy can have its own value in the store. These values are nothing but microtimes, telling us when a particular cache group was cleared for the last time. These keys are evaluated for every cache read to determine if the cache has been invalidated since it was created and should hence be treated as inexistent.

Although deep hierarchies are possible, they are not recommended. Try to keep your cache groups as shallow as possible. Anything up 3-5 parents should be ok. So »a|b|c« is a good depth where »a|b|c|d|e|f|g|h|i|j|k« isn't. Try to join correlating cache groups: if your cache groups look somewhat like »a|b|$page|$items|$whatever« consider using »a|b|c|$page-$items-$whatever« instead.

Summary

Methods
Properties
Constants
populate()
populateTimestamp()
process()
writeCachedContent()
getCachedContent()
clearAll()
clear()
locked()
hasLock()
acquireLock()
releaseLock()
load()
invalidLoadedCache()
$resources
No constants found
getTemplateUid()
sanitize()
fetch()
addMetaTimestamp()
getMetaTimestamp()
invalidate()
getLatestInvalidationTimestamp()
listInvalidationKeys()
read()
write()
delete()
purge()
$sysplugins
$contents
$timestamps
N/A
No private methods found
No private properties found
N/A

Properties

$resources

$resources : array

cache for Smarty_CacheResource instances

Type

array

$sysplugins

$sysplugins : array

resource types provided by the core

Type

array

$contents

$contents : array

cache for contents

Type

array

$timestamps

$timestamps : array

cache for timestamps

Type

array

Methods

populate()

populate(\Smarty_Template_Cached  $cached, \Smarty_Internal_Template  $_template) : void

populate Cached Object with meta data from Resource

Parameters

\Smarty_Template_Cached $cached

cached object

\Smarty_Internal_Template $_template

template object

populateTimestamp()

populateTimestamp(\Smarty_Template_Cached  $cached) : void

populate Cached Object with timestamp and exists from Resource

Parameters

\Smarty_Template_Cached $cached

cached object

process()

process(\Smarty_Internal_Template  $_template, \Smarty_Template_Cached  $cached = null) : \booelan

Read the cached template and process the header

Parameters

\Smarty_Internal_Template $_template

template object

\Smarty_Template_Cached $cached

cached object

Returns

\booelan —

true or false if the cached content does not exist

writeCachedContent()

writeCachedContent(\Smarty_Internal_Template  $_template, string  $content) : boolean

Write the rendered template output to cache

Parameters

\Smarty_Internal_Template $_template

template object

string $content

content to cache

Returns

boolean —

success

getCachedContent()

getCachedContent(\Smarty_Internal_Template  $_template) 

Return cached content

Parameters

\Smarty_Internal_Template $_template

template object

clearAll()

clearAll(\Smarty  $smarty, integer  $exp_time = null) : integer

Empty cache

Parameters

\Smarty $smarty

Smarty object

integer $exp_time

expiration time [being ignored]

Returns

integer —

number of cache files deleted [always -1]

clear()

clear(\Smarty  $smarty, string  $resource_name, string  $cache_id, string  $compile_id, integer  $exp_time) : integer

Empty cache for a specific template

Parameters

\Smarty $smarty

Smarty object

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

integer $exp_time

expiration time [being ignored]

Returns

integer —

number of cache files deleted [always -1]

hasLock()

hasLock(\Smarty  $smarty, \Smarty_Template_Cached  $cached) : \booelan

Check is cache is locked for this template

Parameters

\Smarty $smarty

Smarty object

\Smarty_Template_Cached $cached

cached object

Returns

\booelan —

true or false if cache is locked

acquireLock()

acquireLock(\Smarty  $smarty, \Smarty_Template_Cached  $cached) 

Lock cache for this template

Parameters

\Smarty $smarty

Smarty object

\Smarty_Template_Cached $cached

cached object

releaseLock()

releaseLock(\Smarty  $smarty, \Smarty_Template_Cached  $cached) 

Unlock cache for this template

Parameters

\Smarty $smarty

Smarty object

\Smarty_Template_Cached $cached

cached object

load()

load(\Smarty  $smarty, string  $type = null) : \Smarty_CacheResource

Load Cache Resource Handler

Parameters

\Smarty $smarty

Smarty object

string $type

name of the cache resource

Returns

\Smarty_CacheResource

Cache Resource Handler

invalidLoadedCache()

invalidLoadedCache(\Smarty  $smarty) 

Invalid Loaded Cache Files

Parameters

\Smarty $smarty

Smarty object

getTemplateUid()

getTemplateUid(\Smarty  $smarty, string  $resource_name, string  $cache_id, string  $compile_id) : string

Get template's unique ID

Parameters

\Smarty $smarty

Smarty object

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

Returns

string —

filepath of cache file

sanitize()

sanitize(string  $string) : string

Sanitize CacheID components

Parameters

string $string

CacheID component to sanitize

Returns

string —

sanitized CacheID component

fetch()

fetch(string  $cid, string  $resource_name = null, string  $cache_id = null, string  $compile_id = null, string  $content = null,   $timestamp = null, string  $resource_uid = null) : boolean

Fetch and prepare a cache object.

Parameters

string $cid

CacheID to fetch

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

string $content

cached content

$timestamp
string $resource_uid

resource's uid

Returns

boolean —

success

addMetaTimestamp()

addMetaTimestamp(  $content) 

Add current microtime to the beginning of $cache_content

Parameters

$content

getMetaTimestamp()

getMetaTimestamp(  $content) : float

Extract the timestamp the $content was cached

Parameters

$content

Returns

float —

the microtime the content was cached

invalidate()

invalidate(string  $cid = null, string  $resource_name = null, string  $cache_id = null, string  $compile_id = null, string  $resource_uid = null) : void

Invalidate CacheID

Parameters

string $cid

CacheID

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

string $resource_uid

source's uid

getLatestInvalidationTimestamp()

getLatestInvalidationTimestamp(string  $cid, string  $resource_name = null, string  $cache_id = null, string  $compile_id = null, string  $resource_uid = null) : float

Determine the latest timestamp known to the invalidation chain

Parameters

string $cid

CacheID to determine latest invalidation timestamp of

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

string $resource_uid

source's filepath

Returns

float —

the microtime the CacheID was invalidated

listInvalidationKeys()

listInvalidationKeys(string  $cid, string  $resource_name = null, string  $cache_id = null, string  $compile_id = null, string  $resource_uid = null) : array

Translate a CacheID into the list of applicable InvalidationKeys.

Splits "some|chain|into|an|array" into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )

Parameters

string $cid

CacheID to translate

string $resource_name

template name

string $cache_id

cache id

string $compile_id

compile id

string $resource_uid

source's filepath

Returns

array —

list of InvalidationKeys

read()

read(array  $keys) : array

Read values for a set of keys from cache

Parameters

array $keys

list of keys to fetch

Returns

array —

list of values with the given keys used as indexes

write()

write(array  $keys, integer  $expire = null) : boolean

Save values for a set of keys to cache

Parameters

array $keys

list of values to save

integer $expire

expiration time

Returns

boolean —

true on success, false on failure

delete()

delete(array  $keys) : boolean

Remove values from cache

Parameters

array $keys

list of keys to delete

Returns

boolean —

true on success, false on failure

purge()

purge() : boolean

Remove *all* values from cache

Returns

boolean —

true on success, false on failure