Class Smarty_CacheResource_KeyValueStore

Description

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.

  • author: Rodney Rehm
  • abstract:

Located in /libs/sysplugins/smarty_cacheresource_keyvaluestore.php (line 34)

Smarty_CacheResource
   |
   --Smarty_CacheResource_KeyValueStore
Direct descendents
Class Description
Smarty_CacheResource_Apc APC CacheResource
Smarty_CacheResource_Memcache Memcache CacheResource
Variable Summary
array $contents
array $timestamps
Method Summary
void acquireLock (Smarty $smarty, Smarty_Template_Cached $cached)
void addMetaTimestamp (string &$content)
string buildCachedFilepath (Smarty $smarty, string $resource_name, string $cache_id, string $compile_id)
integer clear (Smarty $smarty, string $resource_name, string $cache_id, string $compile_id, integer $exp_time)
integer clearAll (Smarty $smarty, [integer $exp_time = null])
boolean delete ( $keys)
boolean fetch (string $cid, [string $resource_name = null], [string $cache_id = null], [string $compile_id = null], [ &$content = null], [integer &$timestamp = null], string $content)
float getLatestInvalidationTimestamp (string $cid, [string $resource_name = null], [string $cache_id = null], [string $compile_id = null])
float getMetaTimestamp (string &$content)
booelan hasLock (Smarty $smarty, Smarty_Template_Cached $cached)
void invalidate ([string $cid = null], [string $resource_name = null], [string $cache_id = null], [string $compile_id = null])
array listInvalidationKeys (string $cid, [string $resource_name = null], [string $cache_id = null], [string $compile_id = null])
booelan process (Smarty_Internal_Template $_template, [Smarty_Template_Cached $cached = null])
boolean purge ()
array read ( $keys)
void releaseLock (Smarty $smarty, Smarty_Template_Cached $cached)
string sanitize (string $string)
boolean write ( $keys, [int $expire = null])
boolean writeCachedContent (Smarty_Internal_Template $_template, string $content)
Variables
array $contents = array() (line 40)

cache for contents

  • access: protected
array $timestamps = array() (line 45)

cache for timestamps

  • access: protected

Inherited Variables

Inherited from Smarty_CacheResource

Smarty_CacheResource::$resources
Smarty_CacheResource::$sysplugins
Methods
acquireLock (line 393)

Lock cache for this template

  • access: public
void acquireLock (Smarty $smarty, Smarty_Template_Cached $cached)

Redefinition of:
Smarty_CacheResource::acquireLock()
addMetaTimestamp (line 237)

Add current microtime to the beginning of $cache_content

  • access: protected
void addMetaTimestamp (string &$content)
  • string &$content: the content to be cached
buildCachedFilepath (line 172)

Get system filepath to cached file.

string buildCachedFilepath (Smarty $smarty, string $resource_name, string $cache_id, string $compile_id)
  • Smarty $smarty: Smarty object
  • string $resource_name: template name
  • string $cache_id: cache id
  • string $compile_id: compile id
clear (line 154)

Empty cache for a specific template

integer clear (Smarty $smarty, string $resource_name, string $cache_id, string $compile_id, integer $exp_time)
  • 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]

Redefinition of:
Smarty_CacheResource::clear()
Empty cache for a specific template
clearAll (line 131)

Empty cache

integer clearAll (Smarty $smarty, [integer $exp_time = null])
  • Smarty $smarty: Smarty object
  • integer $exp_time: expiration time [being ignored]

Redefinition of:
Smarty_CacheResource::clearAll()
Empty cache
delete (line 436)

Remove values from cache

boolean delete ( $keys)
  • array $keys: list of keys to delete

Redefined in descendants as:
fetch (line 213)

Fetch and prepare a cache object.

  • return: success
  • access: protected
boolean fetch (string $cid, [string $resource_name = null], [string $cache_id = null], [string $compile_id = null], [ &$content = null], [integer &$timestamp = null], string $content)
  • string $cid: CacheID to fetch
  • string $resource_name: template name
  • string $cache_id: cache id
  • string $compile_id: compile id
  • string $content: cached content
  • integer &$timestamp: cached timestamp (epoch)
  • &$content
getLatestInvalidationTimestamp (line 303)

Determine the latest timestamp known to the invalidation chain

  • return: the microtime the CacheID was invalidated
  • access: protected
float getLatestInvalidationTimestamp (string $cid, [string $resource_name = null], [string $cache_id = null], [string $compile_id = null])
  • string $cid: CacheID to determine latest invalidation timestamp of
  • string $resource_name: template name
  • string $cache_id: cache id
  • string $compile_id: compile id
getMetaTimestamp (line 250)

Extract the timestamp the $content was cached

  • return: the microtime the content was cached
  • access: protected
float getMetaTimestamp (string &$content)
  • string &$content: the cached content
hasLock (line 380)

Check is cache is locked for this template

  • return: true or false if cache is locked
  • access: public
booelan hasLock (Smarty $smarty, Smarty_Template_Cached $cached)

Redefinition of:
Smarty_CacheResource::hasLock()
invalidate (line 267)

Invalidate CacheID

void invalidate ([string $cid = null], [string $resource_name = null], [string $cache_id = null], [string $compile_id = null])
  • string $cid: CacheID
  • string $resource_name: template name
  • string $cache_id: cache id
  • string $compile_id: compile id
listInvalidationKeys (line 334)

Translate a CacheID into the list of applicable InvalidationKeys.

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

  • return: list of InvalidationKeys
  • access: protected
  • uses: $invalidationKeyPrefix - to prepend to each InvalidationKey
array listInvalidationKeys (string $cid, [string $resource_name = null], [string $cache_id = null], [string $compile_id = null])
  • string $cid: CacheID to translate
  • string $resource_name: template name
  • string $cache_id: cache id
  • string $compile_id: compile id
populate (line 54)

populate Cached Object with meta data from Resource

  • access: public
void populate (Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)

Redefinition of:
Smarty_CacheResource::populate()
populate Cached Object with meta data from Resource
populateTimestamp (line 70)

populate Cached Object with timestamp and exists from Resource

  • access: public
void populateTimestamp (Smarty_Template_Cached $cached)

Redefinition of:
Smarty_CacheResource::populateTimestamp()
populate Cached Object with timestamp and exists from Resource
process (line 87)

Read the cached template and process the header

  • return: true or false if the cached content does not exist
  • access: public
booelan process (Smarty_Internal_Template $_template, [Smarty_Template_Cached $cached = null])

Redefinition of:
Smarty_CacheResource::process()
Read the cached template and process header
purge (line 443)

Remove *all* values from cache

boolean purge ()

Redefined in descendants as:
read (line 419)

Read values for a set of keys from cache

  • return: list of values with the given keys used as indexes
  • abstract:
  • access: protected
array read ( $keys)
  • array $keys: list of keys to fetch

Redefined in descendants as:
releaseLock (line 406)

Unlock cache for this template

  • access: public
void releaseLock (Smarty $smarty, Smarty_Template_Cached $cached)

Redefinition of:
Smarty_CacheResource::releaseLock()
sanitize (line 192)

Sanitize CacheID components

string sanitize (string $string)
  • string $string: CacheID component to sanitize
write (line 428)

Save values for a set of keys to cache

  • return: true on success, false on failure
  • abstract:
  • access: protected
boolean write ( $keys, [int $expire = null])
  • array $keys: list of values to save
  • int $expire: expiration time

Redefined in descendants as:
writeCachedContent (line 114)

Write the rendered template output to cache

  • return: success
  • access: public
boolean writeCachedContent (Smarty_Internal_Template $_template, string $content)

Redefinition of:
Smarty_CacheResource::writeCachedContent()
Write the rendered template output to cache

Inherited Methods

Inherited From Smarty_CacheResource

Smarty_CacheResource::acquireLock()
Smarty_CacheResource::clear()
Smarty_CacheResource::clearAll()
Smarty_CacheResource::getCachedContent()
Smarty_CacheResource::hasLock()
Smarty_CacheResource::invalidLoadedCache()
Smarty_CacheResource::load()
Smarty_CacheResource::locked()
Smarty_CacheResource::populate()
Smarty_CacheResource::populateTimestamp()
Smarty_CacheResource::process()
Smarty_CacheResource::releaseLock()
Smarty_CacheResource::writeCachedContent()

Documentation generated on Sun, 11 Sep 2011 11:03:03 +0200 by phpDocumentor 1.4.1