mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-07-29 23:38:50 +02:00
- SelectionModeMixin + CollapsingHeaderScrollMixin extracted; local/downloaded album screens now share AlbumTrackTile, AlbumScaffoldBody, DestructiveSelectionButton, HeaderMetaRow, and confirmAndDeleteTracks - track_detail_actions.dart: shared downloadSingleTrack, queueTracksSkippingDownloaded, download-all confirm, queued snackbar, release-date formatter, list footer, love-all - TtlCache<T> replaces the copied 10-minute static caches; album fetch branches share _applyAlbumMetadata - playlist error card now uses ErrorCard; formatMegabytes shared by queue tab and update dialog
28 lines
618 B
Dart
28 lines
618 B
Dart
/// Simple in-memory cache where each entry expires after [ttl].
|
|
class TtlCache<T> {
|
|
final Duration ttl;
|
|
final Map<String, _TtlEntry<T>> _entries = {};
|
|
|
|
TtlCache(this.ttl);
|
|
|
|
T? get(String key) {
|
|
final entry = _entries[key];
|
|
if (entry == null) return null;
|
|
if (DateTime.now().isAfter(entry.expiresAt)) {
|
|
_entries.remove(key);
|
|
return null;
|
|
}
|
|
return entry.value;
|
|
}
|
|
|
|
void set(String key, T value) {
|
|
_entries[key] = _TtlEntry(value, DateTime.now().add(ttl));
|
|
}
|
|
}
|
|
|
|
class _TtlEntry<T> {
|
|
final T value;
|
|
final DateTime expiresAt;
|
|
_TtlEntry(this.value, this.expiresAt);
|
|
}
|