<?php
/**
 * @file qtrRateLimitCache.php
 * @brief Rate limit cache storage wrapper for bot protection data
 *
 * Provides unified storage interface:
 * - get/set/delete operations with TTL
 * - atomic increment operations
 * - Key prefixing for namespace isolation
 *
 * Can be swapped to wp_cache_* for object cache support if desired.
 */

if (!defined('ABSPATH')) { exit; }

final class CQtrRateLimitCache
{
    /** Avoid huge keys; include prefix */
    private static function k(string $key): string
    {
        return 'qtrbp_' . $key;
    }

    public static function get(string $key)
    {
        return get_transient(self::k($key));
    }

    public static function set(string $key, $value, int $ttlSeconds): bool
    {
        return set_transient(self::k($key), $value, $ttlSeconds);
    }

    public static function delete(string $key): bool
    {
        return delete_transient(self::k($key));
    }

    public static function incr(string $key, int $ttlSeconds, int $by = 1): int
    {
        $v = self::get($key);
        $v = is_numeric($v) ? (int)$v : 0;
        $v += $by;
        self::set($key, $v, $ttlSeconds);
        return $v;
    }
}
?>
