Completed
Push — stable7 ( 35746e...825360 )
by
unknown
29:41
created

apc.php ➔ OC\Memcache\apc_exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 5
rs 9.4285
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $success of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
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 . '/');
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