pub struct SmartCache {
config: Arc<Mutex<CacheConfig>>,
album_play_history: Arc<Mutex<HashMap<String, Vec<String>>>>,
}Expand description
Smart caching engine
Fields§
§config: Arc<Mutex<CacheConfig>>§album_play_history: Arc<Mutex<HashMap<String, Vec<String>>>>Track recently played items per album
Implementations§
Source§impl SmartCache
impl SmartCache
pub fn new(config: CacheConfig) -> Self
Sourcepub fn update_config(&self, config: CacheConfig)
pub fn update_config(&self, config: CacheConfig)
Update configuration
Sourcepub fn should_precache_queue(&self) -> bool
pub fn should_precache_queue(&self) -> bool
Check if should pre-cache queue items.
Note this deliberately does NOT consult wifi_only. It used to return
queue_precache_enabled && !wifi_only, which disabled precaching
outright whenever the user enabled WiFi-only — regardless of the network
actually in use. The network check now lives in the download queue pump
(downloads_allowed_on_current_network), which is the single gate for
all download traffic, so this only answers “is precaching enabled?”.
TRACES: UR-053 | DR-074
Sourcepub fn queue_precache_count(&self) -> usize
pub fn queue_precache_count(&self) -> usize
Get number of queue items to pre-cache
Sourcepub fn track_play(&self, item_id: &str, album_id: Option<&str>)
pub fn track_play(&self, item_id: &str, album_id: Option<&str>)
Track that an item was played
Sourcepub fn should_cache_album(&self, album_id: &str) -> Option<bool>
pub fn should_cache_album(&self, album_id: &str) -> Option<bool>
Check if album affinity threshold reached for caching
Sourcepub fn get_config(&self) -> Option<CacheConfig>
pub fn get_config(&self) -> Option<CacheConfig>
Get configuration
Sourcepub fn get_album_play_history(&self) -> Vec<(String, usize)>
pub fn get_album_play_history(&self) -> Vec<(String, usize)>
Get all tracked albums with their play counts Returns Vec<(album_id, unique_tracks_played)>
Sourcepub async fn get_total_download_size_async<S: DatabaseService>(
&self,
db_service: &Arc<S>,
user_id: &str,
) -> Result<u64, String>
pub async fn get_total_download_size_async<S: DatabaseService>( &self, db_service: &Arc<S>, user_id: &str, ) -> Result<u64, String>
Get total download size for a user (async version)
Sourcepub async fn can_download_async<S: DatabaseService>(
&self,
db_service: &Arc<S>,
user_id: &str,
new_size: u64,
) -> bool
pub async fn can_download_async<S: DatabaseService>( &self, db_service: &Arc<S>, user_id: &str, new_size: u64, ) -> bool
Check if storage limit allows download (async version)
Sourcepub async fn reclaim_expired_async<S: DatabaseService>(
&self,
db_service: &Arc<S>,
user_id: &str,
now: &str,
) -> Result<usize, String>
pub async fn reclaim_expired_async<S: DatabaseService>( &self, db_service: &Arc<S>, user_id: &str, now: &str, ) -> Result<usize, String>
Reclaim temporary downloads whose life limit has passed.
The time-based half of the temporary tier (DR-127); [evict_lru_async]
is the space-pressure half. A row is reclaimed by whichever fires first.
Scoped to download_source = 'auto' for the same reason eviction is: a
'user' row is someone’s own download and has no expiry. COALESCE
guards rows predating migration 012, whose source is NULL and whose
provenance must therefore be treated as the user’s.
Expiry is normally derived — completed_at plus the configured TTL —
rather than stamped at completion. That means a TTL change applies to
entries already on disk instead of only to future ones, and entries
predating the column expire without a backfill. expires_at is honoured
as a per-row override when something sets it.
now is passed in rather than read from the clock so the policy is
testable without sleeping. Both sides go through SQLite’s datetime()
because completed_at is written as CURRENT_TIMESTAMP
(YYYY-MM-DD HH:MM:SS) while callers pass RFC-3339 (…T…+00:00) — a raw
string comparison between the two formats is wrong, since ' ' < 'T'.
Returns the number of entries reclaimed.
TRACES: UR-071 | DR-127 | UT-120
Sourcepub async fn evict_lru_async<S: DatabaseService>(
&self,
db_service: &Arc<S>,
user_id: &str,
space_needed: u64,
) -> Result<u64, String>
pub async fn evict_lru_async<S: DatabaseService>( &self, db_service: &Arc<S>, user_id: &str, space_needed: u64, ) -> Result<u64, String>
Evict least recently used items to make space (async version).
The space-pressure half of the temporary tier; [reclaim_expired_async]
is the time-based half.
Trait Implementations§
Source§impl Clone for SmartCache
impl Clone for SmartCache
Source§fn clone(&self) -> SmartCache
fn clone(&self) -> SmartCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more