get method

T? get(
  1. String key
)

Retrieves an item from the cache using its key.

Returns the item if present and not expired, otherwise returns null.

Implementation

T? get(String key) {
  _logger.debug('Getting item with key: $key');

  final item = _cache[key];

  if (item == null || item.isExpired) {
    if (item != null) {
      _logger.debug('Item with key: $key is expired');
      delete(key); // Delete item if expired
    } else {
      _logger.debug('Item with key: $key not found');
    }

    return null;
  }

  item.updateAccessTime(); // Update the last accessed time

  _logger
    ..debug('Item with key: $key found')
    ..debug('Item with key: $key has value: ${item.value}');

  return item.value;
}