BBCache::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * Class BBCache
4
 *
5
 * @filesource   BBCache.php
6
 * @created      26.04.2018
7
 * @package      chillerlan\BBCode
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\BBCode;
14
15
use Psr\SimpleCache\CacheInterface;
16
17
final class BBCache implements CacheInterface{
18
19
	/**
20
	 * @var array
21
	 */
22
	protected $cache = [];
23
24
	/**
25
	 * @inheritdoc
26
	 */
27
	public function get($key, $default = null){
28
		return $this->cache[$key] ?? $default;
29
	}
30
31
	/**
32
	 * @inheritdoc
33
	 */
34
	public function set($key, $value, $ttl = null){
35
		$this->cache[$key] = $value;
36
37
		return true;
38
	}
39
40
	/**
41
	 * @inheritdoc
42
	 */
43
	public function delete($key){
44
		unset($this->cache[$key]);
45
46
		return true;
47
	}
48
49
	/**
50
	 * @inheritdoc
51
	 */
52
	public function clear(){
53
		$this->cache = [];
54
55
		return true;
56
	}
57
58
	/**
59
	 * @inheritdoc
60
	 */
61
	public function getMultiple($keys, $default = null){
62
		$data = [];
63
64
		foreach($keys as $key){
65
			$data[$key] = $this->cache[$key] ?? $default;
66
		}
67
68
		return $data;
69
	}
70
71
	/**
72
	 * @inheritdoc
73
	 */
74
	public function setMultiple($values, $ttl = null){
75
76
		foreach($values as $key => $value){
77
			$this->cache[$key] = $value;
78
		}
79
80
		return true;
81
	}
82
83
	/**
84
	 * @inheritdoc
85
	 */
86
	public function deleteMultiple($keys){
87
88
		foreach($keys as $key){
89
			unset($this->cache[$key]);
90
		}
91
92
		return true;
93
	}
94
95
	/**
96
	 * @inheritdoc
97
	 */
98
	public function has($key){
99
		return isset($this->cache[$key]);
100
	}
101
102
}
103