]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/demo/plugins/cacheresource.apc.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / demo / plugins / cacheresource.apc.php
1 <?php
2
3 /**
4  * APC CacheResource
5  * CacheResource Implementation based on the KeyValueStore API to use
6  * memcache as the storage resource for Smarty's output caching.
7  * *
8  *
9  * @package CacheResource-examples
10  * @author  Uwe Tews
11  */
12 class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
13 {
14     public function __construct()
15     {
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');
19         }
20     }
21
22     /**
23      * Read values for a set of keys from cache
24      *
25      * @param  array $keys list of keys to fetch
26      *
27      * @return array   list of values with the given keys used as indexes
28      * @return boolean true on success, false on failure
29      */
30     protected function read(array $keys)
31     {
32         $_res = array();
33         $res = apc_fetch($keys);
34         foreach ($res as $k => $v) {
35             $_res[ $k ] = $v;
36         }
37
38         return $_res;
39     }
40
41     /**
42      * Save values for a set of keys to cache
43      *
44      * @param  array $keys   list of values to save
45      * @param  int   $expire expiration time
46      *
47      * @return boolean true on success, false on failure
48      */
49     protected function write(array $keys, $expire = null)
50     {
51         foreach ($keys as $k => $v) {
52             apc_store($k, $v, $expire);
53         }
54
55         return true;
56     }
57
58     /**
59      * Remove values from cache
60      *
61      * @param  array $keys list of keys to delete
62      *
63      * @return boolean true on success, false on failure
64      */
65     protected function delete(array $keys)
66     {
67         foreach ($keys as $k) {
68             apc_delete($k);
69         }
70
71         return true;
72     }
73
74     /**
75      * Remove *all* values from cache
76      *
77      * @return boolean true on success, false on failure
78      */
79     protected function purge()
80     {
81         return apc_clear_cache('user');
82     }
83 }