| Total Complexity | 4 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class ClassBoundMemoryAdapter implements ClassBoundCacheInterface |
||
| 13 | { |
||
| 14 | /** @var array<string, mixed> */ |
||
| 15 | private $items; |
||
| 16 | /** @var ClassBoundCacheInterface */ |
||
| 17 | private $classBoundCache; |
||
| 18 | |||
| 19 | public function __construct(ClassBoundCacheInterface $classBoundCache) |
||
| 20 | { |
||
| 21 | $this->classBoundCache = $classBoundCache; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Fetches an element from the cache by key. |
||
| 26 | * |
||
| 27 | * @return mixed |
||
| 28 | */ |
||
| 29 | public function get(string $key) |
||
| 30 | { |
||
| 31 | if (isset($this->items[$key])) { |
||
| 32 | return $this->items[$key]; |
||
| 33 | } |
||
| 34 | |||
| 35 | return $this->items[$key] = $this->classBoundCache->get($key); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Stores an item in the cache. |
||
| 40 | * |
||
| 41 | * @param mixed $item The item must be serializable. |
||
| 42 | * @param ReflectionClass $refClass If the class is modified, the cache item is invalidated. |
||
| 43 | */ |
||
| 44 | public function set(string $key, $item, ReflectionClass $refClass, ?int $ttl = null): void |
||
| 48 | } |
||
| 49 | } |
||
| 50 |