<?php

declare(strict_types=1);

namespace App\Framework\View\Loading;

final class TemplateCache
{
    private array $cache = [];

    public function __construct(
        private readonly bool $enabled = true
    ) {
    }

    public function get(string $key): ?string
    {
        if (! $this->enabled) {
            return null;
        }

        return $this->cache[$key] ?? null;
    }

    public function set(string $key, string $content): void
    {
        if (! $this->enabled) {
            return;
        }

        $this->cache[$key] = $content;
    }

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

    public function isEnabled(): bool
    {
        return $this->enabled;
    }
}
