use std::path::PathBuf;
use std::time::Duration;
pub mod backends;
pub mod eviction;
pub mod metadata;
pub mod multi;
#[cfg(test)]
mod tests;
pub use metadata::{
CacheEntry, CacheKey, CacheStats, DiskCacheMetadata, LevelStats, SpatialInfo, TileCoord,
};
#[cfg(feature = "cache")]
pub use eviction::{ArcCache, LfuCache, LruTtlCache};
#[cfg(feature = "cache")]
pub use backends::{PersistentDiskCache, SpatialCache, TileCache};
#[cfg(feature = "cache")]
pub use multi::{CacheWarmer, DiskCache, MemoryCache, MultiLevelCache};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum EvictionStrategy {
Lru,
Lfu,
#[default]
Adaptive,
TimeToLive,
LargestFirst,
Random,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum WarmingStrategy {
#[default]
None,
AccessPattern,
SpatialAdjacent,
PyramidLevels,
Custom,
}
#[derive(Debug, Clone)]
pub struct CacheConfig {
pub max_memory_size: usize,
pub max_disk_size: usize,
pub compress: bool,
pub compress_threshold: usize,
pub eviction_strategy: EvictionStrategy,
pub persistent: bool,
pub cache_dir: Option<PathBuf>,
pub default_ttl: Option<Duration>,
pub max_age: Option<Duration>,
pub max_entries: usize,
pub warming_strategy: WarmingStrategy,
pub warm_batch_size: usize,
pub spatial_aware: bool,
pub arc_adaptation_rate: f64,
}
impl Default for CacheConfig {
fn default() -> Self {
Self {
max_memory_size: 100 * 1024 * 1024, max_disk_size: 1024 * 1024 * 1024, compress: true,
compress_threshold: 4096, eviction_strategy: EvictionStrategy::Adaptive,
persistent: true,
cache_dir: None,
default_ttl: Some(Duration::from_secs(3600)), max_age: Some(Duration::from_secs(3600)), max_entries: 10000,
warming_strategy: WarmingStrategy::None,
warm_batch_size: 10,
spatial_aware: false,
arc_adaptation_rate: 0.5,
}
}
}
impl CacheConfig {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_max_memory_size(mut self, size: usize) -> Self {
self.max_memory_size = size;
self
}
#[must_use]
pub fn with_max_disk_size(mut self, size: usize) -> Self {
self.max_disk_size = size;
self
}
#[must_use]
pub fn with_compress(mut self, compress: bool) -> Self {
self.compress = compress;
self
}
#[must_use]
pub fn with_eviction_strategy(mut self, strategy: EvictionStrategy) -> Self {
self.eviction_strategy = strategy;
self
}
#[must_use]
pub fn with_cache_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.cache_dir = Some(dir.into());
self
}
#[must_use]
pub fn with_default_ttl(mut self, ttl: Duration) -> Self {
self.default_ttl = Some(ttl);
self
}
#[must_use]
pub fn with_max_age(mut self, duration: Duration) -> Self {
self.max_age = Some(duration);
self
}
#[must_use]
pub fn with_max_entries(mut self, count: usize) -> Self {
self.max_entries = count;
self
}
#[must_use]
pub fn with_warming_strategy(mut self, strategy: WarmingStrategy) -> Self {
self.warming_strategy = strategy;
self
}
#[must_use]
pub fn with_spatial_aware(mut self, enabled: bool) -> Self {
self.spatial_aware = enabled;
self
}
}