addSessionKey method

void addSessionKey(
  1. String key, {
  2. Response? response,
})

Adds a key to the session-fetched set and stores its data in the L1 RAM cache.

Implementation

void addSessionKey(String key, {Response? response}) {
  if (_disposed) return;

  // Deduplicate: move key to the end to maintain LRU/MRU ordering
  _l1Cache.remove(key);
  _l1Cache[key] = _L1CacheEntry(
    response: response,
    timestamp: DateTime.now(),
  );

  // Enforce limits with a single eviction
  if (_l1Cache.length > LikeConstants.maxL1CacheItems) {
    _l1Cache.remove(_l1Cache.keys.first);
  }
}