5 * CacheResource Implementation based on the KeyValueStore API to use
6 * memcache as the storage resource for Smarty's output caching.
9 * @package CacheResource-examples
12 class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
14 public function __construct()
16 // test if APC is present
17 if (!function_exists('apc_cache_info')) {
18 throw new Exception('APC Template Caching Error: APC is not installed');
23 * Read values for a set of keys from cache
25 * @param array $keys list of keys to fetch
27 * @return array list of values with the given keys used as indexes
28 * @return boolean true on success, false on failure
30 protected function read(array $keys)
33 $res = apc_fetch($keys);
34 foreach ($res as $k => $v) {
42 * Save values for a set of keys to cache
44 * @param array $keys list of values to save
45 * @param int $expire expiration time
47 * @return boolean true on success, false on failure
49 protected function write(array $keys, $expire = null)
51 foreach ($keys as $k => $v) {
52 apc_store($k, $v, $expire);
59 * Remove values from cache
61 * @param array $keys list of keys to delete
63 * @return boolean true on success, false on failure
65 protected function delete(array $keys)
67 foreach ($keys as $k) {
75 * Remove *all* values from cache
77 * @return boolean true on success, false on failure
79 protected function purge()
81 return apc_clear_cache('user');