pub struct TrackCache {
pub recent_tracks: Vec<Track>,
pub artist_tracks: HashMap<String, Vec<Track>>,
pub metadata: CacheMetadata,
}Expand description
Cache structure for storing track data on disk
Fields§
§recent_tracks: Vec<Track>Recent tracks (ordered newest first)
artist_tracks: HashMap<String, Vec<Track>>Artist tracks by artist name
metadata: CacheMetadataCache metadata
Implementations§
Source§impl TrackCache
impl TrackCache
Sourcepub fn load() -> Self
pub fn load() -> Self
Load cache from disk, returns default cache if file doesn’t exist or can’t be read
Sourcepub fn get_recent_tracks(&self, limit: usize) -> &[Track]
pub fn get_recent_tracks(&self, limit: usize) -> &[Track]
Get recent tracks (limited to first n tracks)
Sourcepub fn add_recent_tracks(&mut self, tracks: Vec<Track>)
pub fn add_recent_tracks(&mut self, tracks: Vec<Track>)
Add recent tracks to the cache (merges and maintains order)
Sourcepub fn cache_artist_tracks(&mut self, artist: String, tracks: Vec<Track>)
pub fn cache_artist_tracks(&mut self, artist: String, tracks: Vec<Track>)
Cache artist tracks
Sourcepub fn clear_artist(&mut self, artist: &str)
pub fn clear_artist(&mut self, artist: &str)
Clear cached data for a specific artist
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn get_all_recent_tracks(&self) -> Vec<Track>
pub fn get_all_recent_tracks(&self) -> Vec<Track>
Get all recent tracks (already sorted newest first)
Sourcepub fn get_recent_tracks_limited(&self, limit: usize) -> Vec<Track>
pub fn get_recent_tracks_limited(&self, limit: usize) -> Vec<Track>
Get the N most recent tracks
Sourcepub fn get_most_recent_timestamp(&self) -> Option<DateTime<Utc>>
pub fn get_most_recent_timestamp(&self) -> Option<DateTime<Utc>>
Get the timestamp of the most recent track in cache (if any)
Sourcepub fn merge_recent_tracks(&mut self, new_tracks: Vec<Track>) -> CacheMergeStats
pub fn merge_recent_tracks(&mut self, new_tracks: Vec<Track>) -> CacheMergeStats
Merge new tracks from API into the cache
Sourcepub async fn update_cache_from_api(
&mut self,
client: &(dyn LastFmEditClient + Send + Sync),
fetch_bound: Option<DateTime<Utc>>,
) -> Result<()>
pub async fn update_cache_from_api( &mut self, client: &(dyn LastFmEditClient + Send + Sync), fetch_bound: Option<DateTime<Utc>>, ) -> Result<()>
Update cache with latest tracks from Last.fm API Fetches tracks until we hit EITHER the fetch_bound OR the cache’s most recent timestamp (whichever comes first chronologically). If fetch_bound is None, fetches without lower bound.
Trait Implementations§
Source§impl Clone for TrackCache
impl Clone for TrackCache
Source§fn clone(&self) -> TrackCache
fn clone(&self) -> TrackCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more