/
oiwn
/
capp-rs
Обзор
Документация
Войти
/
oiwn
/
capp-rs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
capp-cache/src/cache.rs
51 строка
2 KB
oiwn
cache implementation
02 мар 2025, 20:22
02 мар 2025, 20:22
450516f
Код
Авторство
О чём код?
use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; /// HTTP-specific cache payload #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct HttpCachePayload { /// The HTTP response body pub body: String, /// HTTP response headers pub headers: HashMap<String, String>, /// Additional metadata about the request/response pub metadata: Option<HashMap<String, String>>, } /// Represents the state of a cached entry #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "lowercase")] pub enum CacheEntryState { /// Recently cached, valid Fresh, /// Needs refresh but usable Stale, /// Must be refreshed before use (invalid page, but loaded) Invalid, /// Failed to cache properly Error, } /// A generic cached entry with HTTP-specific fields #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CacheEntry<T> { /// Unique identifier for this cache entry pub key: String, /// The cached payload pub value: T, /// HTTP response status code pub status_code: u16, /// Current state of the cache entry pub state: CacheEntryState, /// When this entry was first created #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")] pub created_at: DateTime<Utc>, /// When this entry was last accessed #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")] pub last_accessed: DateTime<Utc>, /// Number of errors encountered for this entry pub error_count: i32, /// Most recent error message pub last_error: Option<String>, }