Passed
Push — master ( fd0d63...16794a )
by smiley
01:53
created

APCUCache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 32
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A clear() 0 2 1
A set() 0 4 1
A delete() 0 4 1
A get() 0 10 2
1
<?php
2
/**
3
 * Class APCUCache
4
 *
5
 * @filesource   APCUCache.php
6
 * @created      27.05.2017
7
 * @package      chillerlan\SimpleCache
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\SimpleCache;
14
15
class APCUCache extends CacheDriverAbstract{
16
17
	/** @inheritdoc */
18
	public function get($key, $default = null){
19
		$this->checkKey($key);
20
21
		$value = apcu_fetch($key);
22
23
		if($value !== false){
24
			return $value;
25
		}
26
27
		return $default;
28
	}
29
30
	/** @inheritdoc */
31
	public function set($key, $value, $ttl = null):bool{
32
		$this->checkKey($key);
33
34
		return (bool)apcu_store($key, $value, $this->getTTL($ttl));
35
	}
36
37
	/** @inheritdoc */
38
	public function delete($key):bool{
39
		$this->checkKey($key);
40
41
		return (bool)apcu_delete($key);
42
	}
43
44
	/** @inheritdoc */
45
	public function clear():bool{
46
		return apcu_clear_cache();
47
	}
48
49
}
50