1 | <?php |
||
11 | class MemcachedAdapter extends AbstractAdapter implements AdapterInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var int |
||
15 | */ |
||
16 | protected $ttl; |
||
17 | |||
18 | /** |
||
19 | * @var Memcached |
||
20 | */ |
||
21 | protected $memcached; |
||
22 | |||
23 | public function __construct(array $config = []) |
||
24 | { |
||
25 | $this->validateMemcacheConfiguration($config); |
||
26 | |||
27 | // default config |
||
28 | $this->ttl = 0; |
||
29 | |||
30 | // config |
||
31 | if (isset($config['ttl'])) { |
||
32 | $this->ttl = $config['ttl']; |
||
33 | } |
||
34 | |||
35 | $persistentId = null; |
||
36 | if (isset($config['connection_persistent']) && $config['connection_persistent']) { |
||
37 | $persistentId = '1'; |
||
38 | |||
39 | if (isset($config['pool_size']) && $config['pool_size'] > 1) { |
||
40 | $persistentId = (string) mt_rand(1, $config['pool_size']); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | $this->memcached = new Memcached($persistentId); |
||
45 | $this->memcached->addServers($config['servers']); |
||
46 | |||
47 | if (isset($config['options']) && !empty($config['options'])) { |
||
48 | $this->memcached->setOptions($config['options']); |
||
|
|||
49 | } |
||
50 | |||
51 | if ($this->namespace) { |
||
52 | $this->memcached->setOption(Memcached::OPT_PREFIX_KEY, $this->namespace); |
||
53 | } |
||
54 | |||
55 | if (isset($config['cache_not_found_keys'])) { |
||
56 | $this->cacheNotFoundKeys = (bool) $config['cache_not_found_keys']; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | public function get(string $key) |
||
61 | { |
||
62 | $value = $this->memcached->get($key); |
||
63 | |||
64 | if ($this->memcached->getResultCode() == Memcached::RES_NOTFOUND) { |
||
65 | throw new KeyNotFoundException(); |
||
66 | } |
||
67 | |||
68 | return $value; |
||
69 | } |
||
70 | |||
71 | public function getMulti(array $keys): array |
||
72 | { |
||
73 | return $this->memcached->getMulti($keys); |
||
74 | } |
||
75 | |||
76 | public function set(string $key, $value): bool |
||
77 | { |
||
78 | return $this->memcached->set($key, $value, $this->ttl); |
||
79 | } |
||
80 | |||
81 | public function setMulti(array $data): bool |
||
82 | { |
||
83 | return $this->memcached->setMulti($data, $this->ttl); |
||
84 | } |
||
85 | |||
86 | public function contains(string $key): bool |
||
96 | |||
97 | public function delete(string $key): bool |
||
103 | |||
104 | public function deleteMulti(array $keys): bool |
||
105 | { |
||
106 | $this->memcached->deleteMulti($keys); |
||
107 | |||
108 | return true; |
||
110 | |||
111 | public function flush(): bool |
||
115 | |||
116 | protected function validateMemcacheConfiguration(array $config) |
||
140 | |||
141 | public function setNamespace(string $namespace) |
||
146 | } |
||
147 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.