<?php
namespace EveAI\Chat;

class CacheManager {
    private const SETTINGS_CACHE_KEY = 'eveai_settings_cache';
    private const CACHE_EXPIRATION = 3600; // 1 hour

    public static function get_settings(): array {
        $cached = wp_cache_get(self::SETTINGS_CACHE_KEY);

        if ($cached !== false) {
            return $cached;
        }

        $settings = get_option('eveai_chat_settings', []);
        wp_cache_set(self::SETTINGS_CACHE_KEY, $settings, '', self::CACHE_EXPIRATION);

        return $settings;
    }

    public static function clear_settings_cache(): void {
        wp_cache_delete(self::SETTINGS_CACHE_KEY);
    }

    public static function maybe_clear_caches(): void {
        if (defined('WP_CACHE') && WP_CACHE) {
            wp_cache_flush();
        }
    }
}