pub struct ThumbnailCache {
api_client: Arc<ImmichApiClient>,
memory: Mutex<SizedLruCache>,
cache_dir: PathBuf,
small_semaphore: Arc<Semaphore>,
large_semaphore: Arc<Semaphore>,
inflight: Arc<Mutex<HashMap<String, Receiver<Option<Result<Texture, String>>>>>>,
}Expand description
A combined memory (LRU) and disk-based caching manager for remote and local assets.
Fields§
§api_client: Arc<ImmichApiClient>§memory: Mutex<SizedLruCache>§cache_dir: PathBuf§small_semaphore: Arc<Semaphore>§large_semaphore: Arc<Semaphore>§inflight: Arc<Mutex<HashMap<String, Receiver<Option<Result<Texture, String>>>>>>Implementations§
Source§impl ThumbnailCache
impl ThumbnailCache
Sourceconst AUTO_MIN_BYTES: usize
const AUTO_MIN_BYTES: usize
Floor for the auto-sized RAM budget, so very low-memory systems still hold a working set of decoded thumbnails.
const AUTO_MAX_BYTES: usize
const AUTO_FRACTION_PERCENT: usize = 20
Sourcepub fn new(api_client: Arc<ImmichApiClient>) -> Self
pub fn new(api_client: Arc<ImmichApiClient>) -> Self
Construct a new thumbnail cache manager. Disk pruning is handled
centrally by cache_manager at startup, not here.
Sourcepub fn get_cached(&self, asset_id: &str, size: ThumbnailSize) -> Option<Texture>
pub fn get_cached(&self, asset_id: &str, size: ThumbnailSize) -> Option<Texture>
Retrieve a thumbnail texture from memory if present, updating LRU recency.
Sourcepub fn peek_cached(
&self,
asset_id: &str,
size: ThumbnailSize,
) -> Option<Texture>
pub fn peek_cached( &self, asset_id: &str, size: ThumbnailSize, ) -> Option<Texture>
Same as get_cached but does not touch LRU order. Use for read-only
per-frame paint lookups.
Sourcepub fn cache_stats(&self) -> (usize, usize, usize, usize)
pub fn cache_stats(&self) -> (usize, usize, usize, usize)
(entries, current_bytes, max_bytes, evictions_since_last_call).
fn semaphore_for(&self, size: ThumbnailSize) -> Arc<Semaphore> ⓘ
Sourcepub async fn load_thumbnail(
&self,
asset_id: &str,
size: ThumbnailSize,
) -> Result<Texture, String>
pub async fn load_thumbnail( &self, asset_id: &str, size: ThumbnailSize, ) -> Result<Texture, String>
Asynchronously fetch a remote thumbnail with default non-cancellable execution.
Sourcepub async fn load_thumbnail_cancellable<F>(
&self,
asset_id: &str,
size: ThumbnailSize,
is_cancelled: F,
) -> Result<Texture, String>
pub async fn load_thumbnail_cancellable<F>( &self, asset_id: &str, size: ThumbnailSize, is_cancelled: F, ) -> Result<Texture, String>
Asynchronously fetch a remote thumbnail with cancellable hook support.
Sourceasync fn fetch_remote_thumbnail(
&self,
asset_id: &str,
size: ThumbnailSize,
key: &str,
is_cancelled: &dyn Fn() -> bool,
) -> Result<Texture, String>
async fn fetch_remote_thumbnail( &self, asset_id: &str, size: ThumbnailSize, key: &str, is_cancelled: &dyn Fn() -> bool, ) -> Result<Texture, String>
Internal helper that performs the actual network request and disk backup logic.
Sourcepub async fn load_local_thumbnail_cancellable<F>(
&self,
asset_id: &str,
path: &Path,
is_cancelled: F,
) -> Result<Texture, String>
pub async fn load_local_thumbnail_cancellable<F>( &self, asset_id: &str, path: &Path, is_cancelled: F, ) -> Result<Texture, String>
Asynchronously generate a local file thumbnail with cancellable hook support.
Sourceasync fn fetch_local_thumbnail(
&self,
asset_id: &str,
path: &Path,
key: &str,
is_cancelled: &dyn Fn() -> bool,
) -> Result<Texture, String>
async fn fetch_local_thumbnail( &self, asset_id: &str, path: &Path, key: &str, is_cancelled: &dyn Fn() -> bool, ) -> Result<Texture, String>
Internal helper that scales, saves, and loads a local folder asset thumbnail.
Sourcepub fn clear(&self) -> Result<(), String>
pub fn clear(&self) -> Result<(), String>
Purge all memory caches and completely delete the disk cache directory.
Sourcepub fn clear_memory(&self)
pub fn clear_memory(&self)
Drop every cached texture from RAM without touching the disk cache. Invoked when the library window closes so the texture memory is released until the user reopens it.
Sourcefn cache_file(&self, asset_id: &str, size: ThumbnailSize) -> PathBuf
fn cache_file(&self, asset_id: &str, size: ThumbnailSize) -> PathBuf
Return the physical disk cache path for a remote asset thumbnail.
Sourcefn cache_file_local(&self, asset_id: &str) -> PathBuf
fn cache_file_local(&self, asset_id: &str) -> PathBuf
Return the physical disk cache path for a local folder asset thumbnail.
Sourcefn enter_inflight(
&self,
key: &str,
) -> Result<InflightGuard, Receiver<Option<Result<Texture, String>>>>
fn enter_inflight( &self, key: &str, ) -> Result<InflightGuard, Receiver<Option<Result<Texture, String>>>>
Register or join an ongoing in-flight loading request for a key.
Auto Trait Implementations§
impl !Freeze for ThumbnailCache
impl !RefUnwindSafe for ThumbnailCache
impl !UnwindSafe for ThumbnailCache
impl Send for ThumbnailCache
impl Sync for ThumbnailCache
impl Unpin for ThumbnailCache
impl UnsafeUnpin for ThumbnailCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more