ppoppo-infra 0.1.0

Backend-agnostic infrastructure traits for caching, queuing, and messaging
Documentation
//! Backend-agnostic rate limiter trait.

use async_trait::async_trait;

use crate::Result;
use crate::types::RateLimitResult;

/// Sliding window rate limiter operations.
#[async_trait]
pub trait RateLimit: Send + Sync {
    /// Check and consume rate limit (increments counter).
    async fn check(
        &self,
        key: &str,
        max_requests: i32,
        window_seconds: i32,
    ) -> Result<RateLimitResult>;

    /// Check rate limit without incrementing (read-only peek).
    async fn peek(
        &self,
        key: &str,
        max_requests: i32,
        window_seconds: i32,
    ) -> Result<RateLimitResult>;

    /// Reset rate limit for a specific key (clear all windows).
    async fn reset(&self, key: &str) -> Result<usize>;

    // cleanup()은 trait에 포함하지 않는다. Cache와 동일한 이유.
    // PgRateLimit::cleanup(retention_seconds) 참조.
}