]> git.mxchange.org Git - friendica.git/blob - library/Smarty/demo/plugins/cacheresource.apc.php
Merge pull request #1121 from Beanow/hotfix/bug-1105
[friendica.git] / library / Smarty / demo / plugins / cacheresource.apc.php
1 <?php
2
3 /**
4  * APC CacheResource
5  *
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
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      * @return array list of values with the given keys used as indexes
27      * @return boolean true on success, false on failure
28      */
29     protected function read(array $keys)
30     {
31         $_res = array();
32         $res = apc_fetch($keys);
33         foreach ($res as $k => $v) {
34             $_res[$k] = $v;
35         }
36         return $_res;
37     }
38
39     /**
40      * Save values for a set of keys to cache
41      *
42      * @param array $keys list of values to save
43      * @param int $expire expiration time
44      * @return boolean true on success, false on failure
45      */
46     protected function write(array $keys, $expire=null)
47     {
48         foreach ($keys as $k => $v) {
49             apc_store($k, $v, $expire);
50         }
51         return true;
52     }
53
54     /**
55      * Remove values from cache
56      *
57      * @param array $keys list of keys to delete
58      * @return boolean true on success, false on failure
59      */
60     protected function delete(array $keys)
61     {
62         foreach ($keys as $k) {
63             apc_delete($k);
64         }
65         return true;
66     }
67
68     /**
69      * Remove *all* values from cache
70      *
71      * @return boolean true on success, false on failure
72      */
73     protected function purge()
74     {
75         return apc_clear_cache('user');
76     }
77 }