1
|
|
|
<?php |
2
|
|
|
/* zCache |
3
|
|
|
* |
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Affero General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Affero General Public License |
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* APC Cache Class |
20
|
|
|
*/ |
21
|
|
|
class ApcCache extends AbstractCache |
22
|
|
|
{ |
23
|
|
|
public function get($key) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
return unserialize(apc_fetch($key)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $timeout |
30
|
|
|
*/ |
31
|
|
|
public function set($key, $value, $timeout) |
32
|
|
|
{ |
33
|
|
|
return apc_store($key, serialize($value), $timeout); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $timeout |
38
|
|
|
*/ |
39
|
|
|
public function replace($key, $value, $timeout) |
40
|
|
|
{ |
41
|
|
|
if(!apc_exists($key)) |
42
|
|
|
return false; |
43
|
|
|
apc_store($key, serialize($value), $timeout); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $key |
48
|
|
|
*/ |
49
|
|
|
public function delete($key) |
50
|
|
|
{ |
51
|
|
|
return apc_delete($key); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function increment($key, $step = 1, $timeout = 0) |
55
|
|
|
{ |
56
|
|
|
apc_add($key, 0, $timeout); |
57
|
|
|
return apc_inc($key, $step); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function decrement($key, $step = 1, $timeout = 0) |
61
|
|
|
{ |
62
|
|
|
apc_add($key, 0, $timeout); |
63
|
|
|
return apc_dec($key, $step); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function flush() |
67
|
|
|
{ |
68
|
|
|
return apc_clear_cache(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.