<?php
/**
 * Cron: every 5 minutes
 * Schedule: 0,5,10,15,20,25,30,35,40,45,50,55 * * * *
 * php /var/www/sudanna/cron/clear_expired_cache.php
 */
require_once dirname(__DIR__).'/config.php';
try {
    $del1 = db()->prepare("DELETE FROM kv_cache WHERE expires_at < NOW()");
    $del1->execute();
    $c1 = $del1->rowCount();
    try {
        $del2 = db()->prepare("DELETE FROM ai_cache WHERE expires_at < NOW()");
        $del2->execute();
        $c2 = $del2->rowCount();
    } catch (Throwable $ignored) { $c2 = 0; }
    echo "[clear_cache] " . date('Y-m-d H:i:s') . " kv:{$c1} ai:{$c2}\n";
} catch (Throwable $e) {
    error_log("[clear_cache] " . $e->getMessage());
}
