put method

void put(
  1. String key,
  2. AIResponse response
)

Stores a response in the cache with the given key.

Implementation

void put(String key, AIResponse response) {
  // Evict oldest if at capacity
  if (_cache.length >= maxEntries) {
    final oldestKey = _cache.entries
        .reduce((a, b) => a.value.cachedAt.isBefore(b.value.cachedAt) ? a : b)
        .key;
    _cache.remove(oldestKey);
  }

  _cache[key] = _CacheEntry(response);
}