containsKey method

Future<bool> containsKey(
  1. String key
)

Checks if the cache contains a value associated with the given key.

Throws an ArgumentError if the key is empty. Throws a CacheException if there is an error checking the key.

Implementation

Future<bool> containsKey(String key) async {
  try {
    if (key.isEmpty) {
      throw ArgumentError('Key cannot be empty');
    }
    return await _cacheAdapter.containsKey(key);
  } on HiveError catch (e) {
    _log.severe('Failed to check if key exists in cache (HiveError): $e');
    throw CacheException(
        'Failed to check if key exists in cache: ${e.message}');
  } catch (e) {
    _log.severe('Failed to check if key exists in cache (Unknown Error): $e');
    throw CacheException('Failed to check if key exists in cache: $e');
  }
}