1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vectorface\Cache; |
4
|
|
|
|
5
|
|
|
use Psr\SimpleCache\CacheInterface; |
6
|
|
|
use Traversable; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Adapts a Vectorface cache instance to the PSR SimpleCache interface. |
10
|
|
|
*/ |
11
|
|
|
class SimpleCacheAdapter implements CacheInterface |
12
|
|
|
{ |
13
|
|
|
/** @var Cache */ |
14
|
|
|
protected $cache; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Create an adapter over a Vectorface cache instance to the SimpleCache interface. |
18
|
|
|
* |
19
|
|
|
* @param Cache $cache |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Cache $cache) |
22
|
|
|
{ |
23
|
|
|
$this->cache = $cache; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
|
|
public function get($key, $default = null) |
30
|
|
|
{ |
31
|
|
|
return $this->cache->get($key, $default); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritDoc |
36
|
|
|
* @throws Exception\CacheException |
37
|
|
|
*/ |
38
|
|
|
public function set($key, $value, $ttl = null) |
39
|
|
|
{ |
40
|
|
|
return $this->cache->set($key, $value, $ttl); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function delete($key) |
47
|
|
|
{ |
48
|
|
|
return $this->cache->delete($key); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
|
|
public function clear() |
55
|
|
|
{ |
56
|
|
|
return $this->cache->clear(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
* @param array|Traversable $keys |
62
|
|
|
*/ |
63
|
|
|
public function getMultiple($keys, $default = null) |
64
|
|
|
{ |
65
|
|
|
return $this->cache->getMultiple($keys, $default); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritDoc |
70
|
|
|
* @param array|Traversable $values |
71
|
|
|
* @throws Exception\CacheException |
72
|
|
|
*/ |
73
|
|
|
public function setMultiple($values, $ttl = null) |
74
|
|
|
{ |
75
|
|
|
return $this->cache->setMultiple($values, $ttl); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritDoc |
80
|
|
|
* @param array|Traversable $keys |
81
|
|
|
*/ |
82
|
|
|
public function deleteMultiple($keys) |
83
|
|
|
{ |
84
|
|
|
return $this->cache->deleteMultiple($keys); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritDoc |
89
|
|
|
*/ |
90
|
|
|
public function has($key) |
91
|
|
|
{ |
92
|
|
|
return $this->cache->has($key); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|