#[cfg(feature = "adaptive-ttl")]
use crate::cache::{AdaptiveTTLCache, TTLConfig};
#[cfg(feature = "adaptive-ttl")]
use do_memory_core::Episode;
#[cfg(feature = "adaptive-ttl")]
impl super::TursoStorage {
#[cfg(feature = "adaptive-ttl")]
pub fn enable_episode_cache(
&mut self,
config: TTLConfig,
) -> crate::Result<Option<AdaptiveTTLCache<String, Episode>>> {
let cache = AdaptiveTTLCache::new(config).map_err(|e| {
crate::Error::Storage(format!("Failed to create adaptive TTL cache: {}", e))
})?;
Ok(self.episode_cache.replace(cache))
}
#[cfg(feature = "adaptive-ttl")]
pub fn enable_episode_cache_default(&mut self) -> crate::Result<()> {
let cache = AdaptiveTTLCache::default_config().map_err(|e| {
crate::Error::Storage(format!("Failed to create adaptive TTL cache: {}", e))
})?;
self.episode_cache = Some(cache);
Ok(())
}
#[cfg(feature = "adaptive-ttl")]
pub fn disable_episode_cache(&mut self) -> Option<AdaptiveTTLCache<String, Episode>> {
self.episode_cache.take()
}
#[cfg(feature = "adaptive-ttl")]
pub fn is_episode_cache_enabled(&self) -> bool {
self.episode_cache.is_some()
}
#[cfg(feature = "adaptive-ttl")]
pub fn episode_cache_stats(&self) -> Option<crate::cache::CacheStatsSnapshot> {
self.episode_cache.as_ref().map(|c| c.stats())
}
#[cfg(feature = "adaptive-ttl")]
pub async fn clear_episode_cache(&self) {
if let Some(ref cache) = self.episode_cache {
cache.clear().await;
}
}
#[cfg(feature = "adaptive-ttl")]
pub async fn episode_cache_len(&self) -> Option<usize> {
if let Some(ref cache) = self.episode_cache {
Some(cache.len().await)
} else {
None
}
}
}