| Total Complexity | 10 |
| Total Lines | 86 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class DoctrineCacheAdapter implements CacheInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var CacheProvider |
||
| 14 | */ |
||
| 15 | private $driver; |
||
|
|
|||
| 16 | |||
| 17 | /** |
||
| 18 | * @var CacheProvider[] |
||
| 19 | */ |
||
| 20 | private $driverByNamespace = []; |
||
| 21 | |||
| 22 | |||
| 23 | /** |
||
| 24 | * DoctrineCacheAdapter constructor. |
||
| 25 | * |
||
| 26 | * @param CacheProvider $driver |
||
| 27 | */ |
||
| 28 | 18 | public function __construct(CacheProvider $driver) |
|
| 29 | { |
||
| 30 | 18 | $this->driver = $driver; |
|
| 31 | 18 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc} |
||
| 35 | */ |
||
| 36 | 18 | public function get(CacheKey $key) |
|
| 37 | { |
||
| 38 | 18 | $data = $this->namespace($key->namespace())->fetch($key->key()); |
|
| 39 | |||
| 40 | 18 | return $data === false ? null : $data; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 17 | public function set(CacheKey $key, $data) |
|
| 47 | { |
||
| 48 | 17 | $this->namespace($key->namespace())->save($key->key(), $data, $key->lifetime()); |
|
| 49 | 17 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | 1 | public function delete(CacheKey $key) |
|
| 57 | 1 | } |
|
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | 8 | public function flush($namespace) |
|
| 63 | { |
||
| 64 | 8 | $this->namespace($namespace)->deleteAll(); |
|
| 65 | 8 | } |
|
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | 1 | public function clear() |
|
| 76 | } |
||
| 77 | 1 | } |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Get the cache provider for the given namespace |
||
| 81 | * |
||
| 82 | * @param string $ns |
||
| 83 | * |
||
| 84 | * @return CacheProvider |
||
| 85 | */ |
||
| 86 | 18 | private function namespace(string $ns): CacheProvider |
|
| 98 |