1 | <?php |
||
19 | class Apc extends Cache_Method_Abstract |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | protected $title = 'Alternative PHP Cache'; |
||
25 | |||
26 | /** |
||
27 | * Whether to use the APCu functions or the original APC ones. |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $apcu = false; |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 2 | public function __construct($options) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 1 | public function exists($key) |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 1 | public function put($key, $value, $ttl = 120) |
|
55 | { |
||
56 | 1 | $prefixedKey = $this->getprefixedKey($key); |
|
57 | // An extended key is needed to counteract a bug in APC. |
||
58 | 1 | if ($this->apcu) |
|
59 | { |
||
60 | 1 | if ($value === null) |
|
61 | 1 | apcu_delete($prefixedKey); |
|
62 | else |
||
63 | 1 | apcu_store($prefixedKey, $value, $ttl); |
|
64 | } |
||
65 | else |
||
66 | { |
||
67 | if ($value === null) |
||
68 | apc_delete($prefixedKey); |
||
69 | else |
||
70 | apc_store($prefixedKey, $value, $ttl); |
||
71 | } |
||
72 | 1 | } |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 1 | public function get($key, $ttl = 120) |
|
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 1 | public function clean($type = '') |
|
102 | { |
||
103 | 1 | if ($this->apcu) |
|
104 | 1 | apcu_clear_cache(); |
|
105 | // If passed a type, clear that type out |
||
106 | elseif ($type === '' || $type === 'data') |
||
107 | { |
||
108 | apc_clear_cache('user'); |
||
109 | apc_clear_cache('system'); |
||
110 | } |
||
111 | elseif ($type === 'user') |
||
112 | apc_clear_cache('user'); |
||
113 | 1 | } |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | 2 | public function isAvailable() |
|
119 | { |
||
120 | 2 | return function_exists('apc_store') || function_exists('apcu_store'); |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function details() |
||
130 | } |
||
131 |