Files
SpotiFLAC-Mobile/lib/utils/ttl_cache.dart
T
zarzet 44de61a06a refactor(screens): share album-screen scaffolding and track flows
- 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
2026-07-12 19:19:22 +07:00

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);
}