18 * @author Dan Fuhry <dan@enanocms.org> |
18 * @author Dan Fuhry <dan@enanocms.org> |
19 * @license GNU General Public License |
19 * @license GNU General Public License |
20 */ |
20 */ |
21 |
21 |
22 class CacheManager |
22 class CacheManager |
|
23 { |
|
24 public static function factory($backend = 'auto') |
|
25 { |
|
26 if ( function_exists('xcache_set') ) |
|
27 return new CacheManager_XCache(); |
|
28 else |
|
29 return new CacheManager_File(); |
|
30 } |
|
31 } |
|
32 |
|
33 class CacheManager_XCache |
|
34 { |
|
35 private $prefix; |
|
36 |
|
37 /** |
|
38 * Constructor. Merely generates the prefix that will be prepended to cache objects. |
|
39 */ |
|
40 |
|
41 public function __construct() |
|
42 { |
|
43 global $crypto_key; |
|
44 $this->prefix = 'enano' . substr(md5($crypto_key), 0, 8) . '_'; |
|
45 } |
|
46 |
|
47 /** |
|
48 * @see CacheManager_File::fetch() |
|
49 */ |
|
50 |
|
51 public function fetch($cache_id) |
|
52 { |
|
53 return xcache_isset($this->prefix . $cache_id) ? xcache_get($this->prefix . $cache_id) : false; |
|
54 } |
|
55 |
|
56 /** |
|
57 * @see CacheManager_File::store() |
|
58 */ |
|
59 |
|
60 public function store($cache_id, $data, $ttl = 20) |
|
61 { |
|
62 return xcache_set($this->prefix . $cache_id, $data, $ttl * 60); |
|
63 } |
|
64 |
|
65 /** |
|
66 * @see CacheManager_File::purge() |
|
67 */ |
|
68 |
|
69 public function purge($cache_id) |
|
70 { |
|
71 return xcache_unset($this->prefix . $cache_id); |
|
72 } |
|
73 } |
|
74 |
|
75 class CacheManager_File |
23 { |
76 { |
24 /** |
77 /** |
25 * Fetch a cached piece of data. |
78 * Fetch a cached piece of data. |
26 * @param string Cache ID. The timestamp is checked automatically. |
79 * @param string Cache ID. The timestamp is checked automatically. |
27 */ |
80 */ |