Total Complexity | 5 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class SelfValidatingCache implements SelfValidatingCacheInterface |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var CacheInterface |
||
14 | */ |
||
15 | private $cache; |
||
16 | |||
17 | public function __construct(CacheInterface $cache) |
||
18 | { |
||
19 | $this->cache = $cache; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Fetches a value from the cache. |
||
24 | * |
||
25 | * @param string $key The unique key of this item in the cache. |
||
26 | * |
||
27 | * @return mixed The value of the item from the cache, or null in case of cache miss. |
||
28 | */ |
||
29 | public function get(string $key) |
||
30 | { |
||
31 | $item = $this->cache->get($key); |
||
32 | if (!$item instanceof CacheValidatorInterface) { |
||
33 | throw InvalidCacheItemException::create($key); |
||
34 | } |
||
35 | return $item; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
40 | * |
||
41 | * @param string $key The key of the item to store. |
||
42 | * @param mixed $value The value of the item to store, must be serializable. |
||
43 | * |
||
44 | */ |
||
45 | public function set(string $key, $value) |
||
51 | } |
||
52 | } |
||
53 |