1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2012 Bart Visscher <[email protected]> |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. |
6
|
|
|
* See the COPYING-README file. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OC\Memcache; |
10
|
|
|
|
11
|
|
|
class APC extends Cache { |
12
|
|
|
public function get($key) { |
13
|
|
|
$result = apc_fetch($this->getPrefix() . $key, $success); |
14
|
|
|
if (!$success) { |
|
|
|
|
15
|
|
|
return null; |
16
|
|
|
} |
17
|
|
|
return $result; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function set($key, $value, $ttl = 0) { |
21
|
|
|
return apc_store($this->getPrefix() . $key, $value, $ttl); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function hasKey($key) { |
25
|
|
|
return apc_exists($this->getPrefix() . $key); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function remove($key) { |
29
|
|
|
return apc_delete($this->getPrefix() . $key); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function clear($prefix = '') { |
33
|
|
|
$ns = $this->getPrefix() . $prefix; |
34
|
|
|
$ns = preg_quote($ns, '/'); |
35
|
|
|
$iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
36
|
|
|
return apc_delete($iter); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
static public function isAvailable() { |
40
|
|
|
if (!extension_loaded('apc')) { |
41
|
|
|
return false; |
42
|
|
|
} elseif (!ini_get('apc.enabled')) { |
43
|
|
|
return false; |
44
|
|
|
} elseif (!ini_get('apc.enable_cli') && \OC::$CLI) { |
45
|
|
|
return false; |
46
|
|
|
} else { |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (!function_exists('apc_exists')) { |
53
|
|
|
function apc_exists($keys) { |
54
|
|
|
$result = false; |
55
|
|
|
apc_fetch($keys, $result); |
56
|
|
|
return $result; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.