CacheManager class

Manages a two-tier (memory + disk) cache with per-entry TTL.

Usage:

final cache = CacheManager();
await cache.init();
await cache.set('key', {'data': 42}, CacheManager.packageMetadataTtl);
final result = await cache.get('key'); // {'data': 42}

Constructors

CacheManager({String? cacheDir})
Creates a new cache manager.

Properties

cacheDir String
The resolved cache directory path.
no setter
hashCode int
The hash code for this object.
no setterinherited
memoryEntryCount int
Number of entries currently in the memory tier (useful for diagnostics).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<void>
Remove all entries from both tiers.
get(String key) Future<Map<String, dynamic>?>
Retrieve a cached value by key.
init() Future<void>
Ensure the disk cache directory exists.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String key) Future<void>
Remove a specific key from both tiers.
set(String key, Map<String, dynamic> value, Duration ttl) Future<void>
Store a value under key with a given ttl.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

changelogTtl → const Duration
TTL for changelogs that may be updated with new releases.
flutterDocsTtl → const Duration
TTL for Flutter documentation pages.
packageMetadataTtl → const Duration
TTL for pub.flutter-io.cn package metadata (versions list, etc.).
versionDetailsTtl → const Duration
TTL for immutable version-specific data (a released version never changes).