Update lua versions
[ryzomcore.git] / web / private_php / ams / plugins / cacheresource.apc.php
blob00ba598178aca9992b1bdbf08ab07cb1f10d4dde
1 <?php
3 /**
4 * APC CacheResource
6 * CacheResource Implementation based on the KeyValueStore API to use
7 * memcache as the storage resource for Smarty's output caching.
8 * *
9 * @package CacheResource-examples
10 * @author Uwe Tews
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');
22 /**
23 * Read values for a set of keys from cache
25 * @param array $keys list of keys to fetch
26 * @return array list of values with the given keys used as indexes
27 * @return boolean true on success, false on failure
29 protected function read(array $keys)
31 $_res = array();
32 $res = apc_fetch($keys);
33 foreach ($res as $k => $v) {
34 $_res[$k] = $v;
36 return $_res;
39 /**
40 * Save values for a set of keys to cache
42 * @param array $keys list of values to save
43 * @param int $expire expiration time
44 * @return boolean true on success, false on failure
46 protected function write(array $keys, $expire=null)
48 foreach ($keys as $k => $v) {
49 apc_store($k, $v, $expire);
51 return true;
54 /**
55 * Remove values from cache
57 * @param array $keys list of keys to delete
58 * @return boolean true on success, false on failure
60 protected function delete(array $keys)
62 foreach ($keys as $k) {
63 apc_delete($k);
65 return true;
68 /**
69 * Remove *all* values from cache
71 * @return boolean true on success, false on failure
73 protected function purge()
75 return apc_clear_cache('user');