capp_cache/cache.rs
1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5/// HTTP-specific cache payload
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub struct HttpCachePayload {
8 /// The HTTP response body
9 pub body: String,
10 /// HTTP response headers
11 pub headers: HashMap<String, String>,
12 /// Additional metadata about the request/response
13 pub metadata: Option<HashMap<String, String>>,
14}
15
16/// Represents the state of a cached entry
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
18#[serde(rename_all = "lowercase")]
19pub enum CacheEntryState {
20 /// Recently cached, valid
21 Fresh,
22 /// Needs refresh but usable
23 Stale,
24 /// Must be refreshed before use (invalid page, but loaded)
25 Invalid,
26 /// Failed to cache properly
27 Error,
28}
29
30/// A generic cached entry with HTTP-specific fields
31#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
32pub struct CacheEntry<T> {
33 /// Unique identifier for this cache entry
34 pub key: String,
35 /// The cached payload
36 pub value: T,
37 /// HTTP response status code
38 pub status_code: u16,
39 /// Current state of the cache entry
40 pub state: CacheEntryState,
41 /// When this entry was first created
42 pub created_at: DateTime<Utc>,
43 /// When this entry was last accessed
44 pub last_accessed: DateTime<Utc>,
45 /// Number of errors encountered for this entry
46 pub error_count: i32,
47 /// Most recent error message
48 pub last_error: Option<String>,
49}