set method

Future<void> set(
  1. String url,
  2. String content, {
  3. Duration? expiry,
})

Cache content for a URL

Implementation

Future<void> set(
  String url,
  String content, {
  Duration? expiry,
}) async {
  final key = _generateKey(url);
  final expiryDuration = expiry ?? _config.defaultExpiry;
  final now = DateTime.now();

  final entry = CacheEntry(
    content: content,
    cachedAt: now,
    expiresAt: now.add(expiryDuration),
    url: url,
  );

  _memoryCache[key] = entry;

  // Enforce cache size limits
  await _enforceLimits();

  // Persist to disk if enabled
  if (_config.persistToDisk && _cacheFile != null) {
    await _saveToDisk();
  }
}