<?php

namespace App\Framework\Cache\Driver;

use App\Framework\Cache\CacheDriver;
use App\Framework\Cache\CacheItem;

final class InMemoryCache implements CacheDriver
{
    private array $data = [];

    public function get(string $key): CacheItem
    {
        return $this->data[$key] ?? CacheItem::miss($key);
    }

    public function set(string $key, string $value, ?int $ttl = null): bool
    {
        $this->data[$key] = $value;
        return true;
    }

    public function has(string $key): bool
    {
        return isset($this->data[$key]);
    }

    public function forget(string $key): bool
    {
        unset($this->data[$key]);
        return true;
    }

    public function clear(): bool
    {
        unset($this->data);
        return true;
    }
}
