1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum CacheError {
8 #[error("Connection error: {0}")]
9 Connection(String),
10
11 #[error("Serialization error: {0}")]
12 Serialization(#[from] serde_json::Error),
13
14 #[error("Key not found: {0}")]
15 NotFound(String),
16
17 #[error("Cache is full")]
18 CacheFull,
19
20 #[error("Invalid configuration: {0}")]
21 InvalidConfig(String),
22
23 #[error("Backend error: {0}")]
24 Backend(String),
25
26 #[cfg(feature = "redis")]
27 #[error("Redis error: {0}")]
28 Redis(#[from] redis::RedisError),
29}
30
31impl CacheError {
32 pub fn is_transient(&self) -> bool {
34 matches!(self, CacheError::Connection(_) | CacheError::Backend(_))
35 }
36}