<?php

declare(strict_types=1);

namespace ContextPaging;

/**
 * In-memory cache implementation (default, for single-request usage).
 */
class InMemoryCache implements CacheInterface
{
    private array $data = [];

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

    public function set(string $key, mixed $value, ?int $ttl = null): void
    {
        $this->data[$key] = $value;
        // TTL ignored for in-memory (single request scope)
    }

    public function has(string $key): bool
    {
        return array_key_exists($key, $this->data);
    }

    public function delete(string $key): void
    {
        unset($this->data[$key]);
    }

    public function clear(): void
    {
        $this->data = [];
    }
}
