1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Persistence; |
6
|
|
|
|
7
|
|
|
use BadMethodCallException; |
8
|
|
|
use Doctrine\Common\Cache\Cache; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
use Psr\SimpleCache\CacheInterface; |
11
|
|
|
use function sprintf; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
final class SimpleCacheAdapter implements CacheInterface |
17
|
|
|
{ |
18
|
|
|
/** @var Cache */ |
19
|
|
|
private $wrapped; |
20
|
|
|
|
21
|
|
|
public function __construct(Cache $wrapped) |
22
|
|
|
{ |
23
|
|
|
$this->wrapped = $wrapped; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function unwrap() : Cache |
27
|
|
|
{ |
28
|
|
|
return $this->wrapped; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritDoc |
33
|
|
|
*/ |
34
|
|
|
public function get($key, $default = null) |
35
|
|
|
{ |
36
|
|
|
$cachedValue = $this->wrapped->fetch($key); |
37
|
|
|
|
38
|
|
|
return $cachedValue === false ? $default : $cachedValue; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
*/ |
44
|
|
|
public function set($key, $value, $ttl = null) : bool |
45
|
|
|
{ |
46
|
|
|
if ($ttl !== null) { |
47
|
|
|
throw new InvalidArgumentException('Setting a TTL is not supported.'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->wrapped->save($key, $value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritDoc |
55
|
|
|
*/ |
56
|
|
|
public function delete($key) : bool |
57
|
|
|
{ |
58
|
|
|
throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritDoc |
63
|
|
|
*/ |
64
|
|
|
public function clear() : bool |
65
|
|
|
{ |
66
|
|
|
throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritDoc |
71
|
|
|
*/ |
72
|
|
|
public function getMultiple($keys, $default = null) : iterable |
73
|
|
|
{ |
74
|
|
|
throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritDoc |
79
|
|
|
*/ |
80
|
|
|
public function setMultiple($values, $ttl = null) : bool |
81
|
|
|
{ |
82
|
|
|
throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritDoc |
87
|
|
|
*/ |
88
|
|
|
public function deleteMultiple($keys) : bool |
89
|
|
|
{ |
90
|
|
|
throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritDoc |
95
|
|
|
*/ |
96
|
|
|
public function has($key) : bool |
97
|
|
|
{ |
98
|
|
|
return $this->wrapped->contains($key); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|