<?php
namespace PageVICO\Ajax;

defined('ABSPATH') || exit;

use PageVICO\Cache\CacheManager;

class CacheHandler {
    public static function init() {
        add_action('wp_ajax_pagevico_clear_cache', array(__CLASS__, 'clearCache'));
    }

    public static function clearCache() {
        // Verify nonce
        if (!check_ajax_referer('pagevico_clear_cache', 'nonce', false)) {
            wp_send_json_error(array('message' => __('Security check failed', 'page-visit-counter-analytics')));
        }

        // Clear all plugin caches
        CacheManager::clearAll();

        // Send success response
        wp_send_json_success(array('message' => __('Cache cleared successfully', 'page-visit-counter-analytics')));
    }
} 