| Total Complexity | 6 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | trait CacheAwareTrait |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var CacheInterface |
||
| 12 | */ |
||
| 13 | protected $cache; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @return string |
||
| 17 | */ |
||
| 18 | abstract protected function getCachePrefix(): string; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param mixed $key |
||
| 22 | * @param mixed|null $default |
||
| 23 | * @return mixed |
||
| 24 | * @throws InvalidArgumentException |
||
| 25 | */ |
||
| 26 | public function getFromCache($key, $default = null) |
||
| 27 | { |
||
| 28 | return $this->cache->get($key, $default); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param mixed $key |
||
| 33 | * @return bool |
||
| 34 | * @throws InvalidArgumentException |
||
| 35 | */ |
||
| 36 | public function isInCache($key): bool |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param mixed $key |
||
| 43 | * @return bool |
||
| 44 | * @throws InvalidArgumentException |
||
| 45 | */ |
||
| 46 | public function deleteFromCache($key): bool |
||
| 47 | { |
||
| 48 | return $this->cache->delete($key); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param mixed $key |
||
| 53 | * @param mixed $value |
||
| 54 | * @param null $ttl |
||
|
|
|||
| 55 | * @return bool |
||
| 56 | * @throws InvalidArgumentException |
||
| 57 | */ |
||
| 58 | public function setInCache($key, $value, $ttl = null): bool |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * |
||
| 65 | */ |
||
| 66 | public function clearCache() |
||
| 67 | { |
||
| 68 | $this->cache->clear(); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param mixed $key |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | protected function getCacheKey($key): string |
||
| 78 | } |
||
| 79 | } |
||
| 80 |