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 |
string
template name
string
cache id
string
compile id
integer
expiration time [being ignored]
integer
number 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 |
integer
expiration time [being ignored]
integer
number of cache files deleted [always -1]getCachedContent(\Smarty_Internal_Template $_template)
inherited_from | \Smarty_CacheResource::getCachedContent() |
---|
hasLock(\Smarty $smarty, \Smarty_Template_Cached $cached) : \booelan
\booelan
true or false if cache is lockedinvalidLoadedCache(\Smarty $smarty)
load(\Smarty $smarty, string $type) : \Smarty_CacheResource
inherited_from | \Smarty_CacheResource::load() |
---|
string
name of the cache resource
\Smarty_CacheResource
Cache 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
\booelan
true or false if the cached content does not existreleaseLock(\Smarty $smarty, \Smarty_Template_Cached $cached)
writeCachedContent(\Smarty_Internal_Template $_template, string $content) : boolean
string
content to cache
boolean
successaddMetaTimestamp(string $content)
string
&$content the content to be cached
delete(array $keys) : boolean
array
list of keys to delete
boolean
true on success, false on failurefetch(string $cid, string $resource_name, string $cache_id, string $compile_id, string $content, integer $timestamp, string $resource_uid) : boolean
string
CacheID to fetch
string
template name
string
cache id
string
compile id
string
cached content
integer
&$timestamp cached timestamp (epoch)
string
resource's uid
boolean
successgetLatestInvalidationTimestamp(string $cid, string $resource_name, string $cache_id, string $compile_id, string $resource_uid) : float
string
CacheID to determine latest invalidation timestamp of
string
template name
string
cache id
string
compile id
string
source's filepath
float
the microtime the CacheID was invalidatedgetMetaTimestamp(string $content) : float
string
&$content the cached content
float
the microtime the content was cachedgetTemplateUid(\Smarty $smarty, string $resource_name, string $cache_id, string $compile_id) : string
string
template name
string
cache id
string
compile id
string
filepath of cache fileinvalidate(string $cid, string $resource_name, string $cache_id, string $compile_id, string $resource_uid) : void
string
CacheID
string
template name
string
cache id
string
compile id
string
source'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 |
---|
string
CacheID to translate
string
template name
string
cache id
string
compile id
string
source's filepath
array
list of InvalidationKeyspurge() : boolean
boolean
true on success, false on failureread(array $keys) : array
array
list of keys to fetch
array
list of values with the given keys used as indexessanitize(string $string) : string
string
CacheID component to sanitize
string
sanitized CacheID componentwrite(array $keys, int $expire) : boolean
array
list of values to save
int
expiration time
boolean
true on success, false on failure$resources : array
inherited_from | \Smarty_CacheResource::$$resources |
---|
$contents : array
$sysplugins : array
inherited_from | \Smarty_CacheResource::$$sysplugins |
---|