| Total Complexity | 10 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class WithLocalCache implements ICache { |
||
| 12 | private ICache $inner; |
||
| 13 | private CappedMemoryCache $cached; |
||
| 14 | |||
| 15 | public function __construct(ICache $inner, int $localCapacity = 512) { |
||
| 16 | $this->inner = $inner; |
||
| 17 | $this->cached = new CappedMemoryCache($localCapacity); |
||
| 18 | } |
||
| 19 | |||
| 20 | public function get($key) { |
||
| 21 | if (isset($this->cached[$key])) { |
||
| 22 | return $this->cached[$key]; |
||
| 23 | } else { |
||
| 24 | $value = $this->inner->get($key); |
||
| 25 | if (!is_null($value)) { |
||
| 26 | $this->cached[$key] = $value; |
||
| 27 | } |
||
| 28 | return $value; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public function set($key, $value, $ttl = 0) { |
||
| 33 | $this->cached[$key] = $value; |
||
| 34 | return $this->inner->set($key, $value, $ttl); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function hasKey($key) { |
||
| 38 | return isset($this->cached[$key]) || $this->inner->hasKey($key); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function remove($key) { |
||
| 42 | unset($this->cached[$key]); |
||
| 43 | return $this->inner->remove($key); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function clear($prefix = '') { |
||
| 49 | } |
||
| 50 | |||
| 51 | public static function isAvailable(): bool { |
||
| 53 | } |
||
| 54 | } |
||
| 55 |