Skip to main content

ThumbnailCache

Struct ThumbnailCache 

Source
pub struct ThumbnailCache {
    config: Arc<Mutex<CacheConfig>>,
    cache_dir: PathBuf,
}
Expand description

Thumbnail cache with LRU eviction

Fields§

§config: Arc<Mutex<CacheConfig>>§cache_dir: PathBuf

Implementations§

Source§

impl ThumbnailCache

Source

pub fn new(app_data_dir: PathBuf, config: CacheConfig) -> Self

Create a new thumbnail cache

Source

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

Source

pub fn is_enabled(&self) -> bool

Check if caching is enabled

Source

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

Source

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.

Source

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

Source

async fn ensure_space( &self, db: Arc<RusqliteService>, needed_bytes: u64, ) -> Result<(), String>

Ensure there’s enough space by evicting LRU items if needed

Source

async fn evict_lru( &self, db: Arc<RusqliteService>, to_free: u64, ) -> Result<(), String>

Evict least recently used items to free up space

Source

pub async fn get_cache_size(&self, db: Arc<RusqliteService>) -> u64

Get current total cache size in bytes

Source

pub async fn get_item_count(&self, db: Arc<RusqliteService>) -> i64

Get count of cached items

Source

pub async fn get_limit(&self, db: Arc<RusqliteService>) -> u64

Get the current cache limit in bytes

Source

pub async fn set_limit( &self, db: Arc<RusqliteService>, limit_bytes: u64, ) -> Result<(), String>

Set the cache limit in bytes

Source

pub async fn clear_cache(&self, db: Arc<RusqliteService>) -> Result<(), String>

Clear all cached thumbnails

Source

pub async fn delete_item( &self, db: Arc<RusqliteService>, item_id: &str, ) -> Result<(), String>

Delete cached thumbnail for a specific item

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more