get method
Get cached response if fresh. Returns the cached body string or null if miss/stale.
Implementation
Future<String?> get(String url, Map<String, dynamic>? query) async {
if (!db.initialized) return null;
final key = _buildCacheKey(url, query);
final cached = await db.getFromCache(key);
if (cached == null) return null;
final cachedAt = cached['cachedAt'] as int?;
if (cachedAt == null) return null;
final age = DateTime.now().millisecondsSinceEpoch - cachedAt;
if (age <= config.maxAge.inMilliseconds) {
return cached['body'] as String?;
}
if (config.maxStale != null && age <= (config.maxAge + config.maxStale!).inMilliseconds) {
return cached['body'] as String?;
}
return null;
}