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.
| package | Smarty |
|---|---|
| subpackage | Cacher |
| author | Rodney Rehm |
acquireLock(\Smarty $smarty, \Smarty_Template_Cached $cached)
clear(\Smarty $smarty, string $resource_name, string $cache_id, string $compile_id, integer $exp_time) : integer
| uses | to generate the CacheID |
|---|---|
| uses | to mark CacheIDs parent chain as outdated |
| uses | to remove CacheID from cache |
stringtemplate name
stringcache id
stringcompile id
integerexpiration time [being ignored]
integernumber of cache files deleted [always -1]clearAll(\Smarty $smarty, integer $exp_time) : integer
| uses | to clear the whole store |
|---|---|
| uses | to mark everything outdated if purge() is inapplicable |
integerexpiration time [being ignored]
integernumber of cache files deleted [always -1]getCachedContent(\Smarty_Internal_Template $_template)
| inherited_from | \Smarty_CacheResource::getCachedContent() |
|---|
hasLock(\Smarty $smarty, \Smarty_Template_Cached $cached) : \booelan
\booelantrue or false if cache is lockedinvalidLoadedCache(\Smarty $smarty)
load(\Smarty $smarty, string $type) : \Smarty_CacheResource
| inherited_from | \Smarty_CacheResource::load() |
|---|
stringname of the cache resource
\Smarty_CacheResourceCache Resource Handlerlocked(\Smarty $smarty, \Smarty_Template_Cached $cached)
| inherited_from | \Smarty_CacheResource::locked() |
|---|
populate(\Smarty_Template_Cached $cached, \Smarty_Internal_Template $_template) : void
populateTimestamp(\Smarty_Template_Cached $cached) : void
process(\Smarty_Internal_Template $_template, \Smarty_Template_Cached $cached) : \booelan
\booelantrue or false if the cached content does not existreleaseLock(\Smarty $smarty, \Smarty_Template_Cached $cached)
writeCachedContent(\Smarty_Internal_Template $_template, string $content) : boolean
stringcontent to cache
booleansuccessaddMetaTimestamp(string $content)
string&$content the content to be cached
delete(array $keys) : boolean
arraylist of keys to delete
booleantrue on success, false on failurefetch(string $cid, string $resource_name, string $cache_id, string $compile_id, string $content, integer $timestamp, string $resource_uid) : boolean
stringCacheID to fetch
stringtemplate name
stringcache id
stringcompile id
stringcached content
integer&$timestamp cached timestamp (epoch)
stringresource's uid
booleansuccessgetLatestInvalidationTimestamp(string $cid, string $resource_name, string $cache_id, string $compile_id, string $resource_uid) : float
stringCacheID to determine latest invalidation timestamp of
stringtemplate name
stringcache id
stringcompile id
stringsource's filepath
floatthe microtime the CacheID was invalidatedgetMetaTimestamp(string $content) : float
string&$content the cached content
floatthe microtime the content was cachedgetTemplateUid(\Smarty $smarty, string $resource_name, string $cache_id, string $compile_id) : string
stringtemplate name
stringcache id
stringcompile id
stringfilepath of cache fileinvalidate(string $cid, string $resource_name, string $cache_id, string $compile_id, string $resource_uid) : void
stringCacheID
stringtemplate name
stringcache id
stringcompile id
stringsource's uid
listInvalidationKeys(string $cid, string $resource_name, string $cache_id, string $compile_id, string $resource_uid) : array
Splits "some|chain|into|an|array" into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
| uses | to prepend to each InvalidationKey |
|---|
stringCacheID to translate
stringtemplate name
stringcache id
stringcompile id
stringsource's filepath
arraylist of InvalidationKeyspurge() : boolean
booleantrue on success, false on failureread(array $keys) : array
arraylist of keys to fetch
arraylist of values with the given keys used as indexessanitize(string $string) : string
stringCacheID component to sanitize
stringsanitized CacheID componentwrite(array $keys, int $expire) : boolean
arraylist of values to save
intexpiration time
booleantrue on success, false on failure$resources : array
| inherited_from | \Smarty_CacheResource::$$resources |
|---|
$contents : array
$sysplugins : array
| inherited_from | \Smarty_CacheResource::$$sysplugins |
|---|