get method

T? get(
  1. String? key
)

Retrieves an item from the cache.

Returns the item's value if it exists and has not expired. Otherwise, removes the expired item (if it exists) and returns null.

Implementation

T? get(String? key) {
  if (key == null) return null;

  final item = _cache[key];
  if (item != null && !item.isExpired) {
    return item.value;
  }
  // Clean up expired or non-existent entries.
  _cache.remove(key);
  return null;
}