putWithDuration method

void putWithDuration(
  1. String key,
  2. T item,
  3. Duration duration
)

Inserts an item with the given key and duration into the cache

Implementation

void putWithDuration(String key, T item, Duration duration) {
  final endTime = _nowInSeconds() + duration.inSeconds;

  final CacheItem<T> cacheItem = CacheItem<T>(key, item, endTime);
  _cache.add(cacheItem);

  // Try to start the timer if not done yet
  _tryStartTimer();
}