pub struct ThumbnailCache {
config: Arc<Mutex<CacheConfig>>,
cache_dir: PathBuf,
}Expand description
Thumbnail cache with LRU eviction
Fields§
§config: Arc<Mutex<CacheConfig>>§cache_dir: PathBufImplementations§
Source§impl ThumbnailCache
impl ThumbnailCache
Sourcepub fn new(app_data_dir: PathBuf, config: CacheConfig) -> Self
pub fn new(app_data_dir: PathBuf, config: CacheConfig) -> Self
Create a new thumbnail cache
Sourcefn resolve_in_cache_dir(&self, filename: &str) -> Result<PathBuf, String>
fn resolve_in_cache_dir(&self, filename: &str) -> Result<PathBuf, String>
Resolve a cache filename against the cache directory, refusing anything that lands outside it.
.. is folded away lexically rather than through canonicalize, so a
file that does not exist yet still resolves — the same approach as
media_server::resolve_path. safe_component should already have made an
escape impossible; this is the check at the point of use.
TRACES: | DR-210 | UT-204
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if caching is enabled
Sourcepub async fn get_cached_path(
&self,
db: Arc<RusqliteService>,
item_id: &str,
image_type: &str,
tag: &str,
) -> Option<PathBuf>
pub async fn get_cached_path( &self, db: Arc<RusqliteService>, item_id: &str, image_type: &str, tag: &str, ) -> Option<PathBuf>
Get cached thumbnail path, or None if not cached Updates last_accessed timestamp for LRU tracking
Sourceasync fn touch(
&self,
db: &Arc<RusqliteService>,
item_id: &str,
image_type: &str,
tag: Option<&str>,
)
async fn touch( &self, db: &Arc<RusqliteService>, item_id: &str, image_type: &str, tag: Option<&str>, )
Update last_accessed for LRU tracking. When tag is Some, scope to
that exact row; when None, touch every row for the item + type.
Sourcepub async fn save_thumbnail(
&self,
db: Arc<RusqliteService>,
item_id: &str,
image_type: &str,
tag: &str,
data: &[u8],
width: Option<i32>,
height: Option<i32>,
) -> Result<PathBuf, String>
pub async fn save_thumbnail( &self, db: Arc<RusqliteService>, item_id: &str, image_type: &str, tag: &str, data: &[u8], width: Option<i32>, height: Option<i32>, ) -> Result<PathBuf, String>
Save thumbnail to cache
TRACES: | DR-210 | UT-204
Sourceasync fn ensure_space(
&self,
db: Arc<RusqliteService>,
needed_bytes: u64,
) -> Result<(), String>
async fn ensure_space( &self, db: Arc<RusqliteService>, needed_bytes: u64, ) -> Result<(), String>
Ensure there’s enough space by evicting LRU items if needed
Sourceasync fn evict_lru(
&self,
db: Arc<RusqliteService>,
to_free: u64,
) -> Result<(), String>
async fn evict_lru( &self, db: Arc<RusqliteService>, to_free: u64, ) -> Result<(), String>
Evict least recently used items to free up space
Sourcepub async fn get_cache_size(&self, db: Arc<RusqliteService>) -> u64
pub async fn get_cache_size(&self, db: Arc<RusqliteService>) -> u64
Get current total cache size in bytes
Sourcepub async fn get_item_count(&self, db: Arc<RusqliteService>) -> i64
pub async fn get_item_count(&self, db: Arc<RusqliteService>) -> i64
Get count of cached items
Sourcepub async fn get_limit(&self, db: Arc<RusqliteService>) -> u64
pub async fn get_limit(&self, db: Arc<RusqliteService>) -> u64
Get the current cache limit in bytes
Sourcepub async fn set_limit(
&self,
db: Arc<RusqliteService>,
limit_bytes: u64,
) -> Result<(), String>
pub async fn set_limit( &self, db: Arc<RusqliteService>, limit_bytes: u64, ) -> Result<(), String>
Set the cache limit in bytes
Sourcepub async fn clear_cache(&self, db: Arc<RusqliteService>) -> Result<(), String>
pub async fn clear_cache(&self, db: Arc<RusqliteService>) -> Result<(), String>
Clear all cached thumbnails
Sourcepub async fn delete_item(
&self,
db: Arc<RusqliteService>,
item_id: &str,
) -> Result<(), String>
pub async fn delete_item( &self, db: Arc<RusqliteService>, item_id: &str, ) -> Result<(), String>
Delete cached thumbnail for a specific item