forget method

  1. @override
Future<void> forget(
  1. String key
)
override

Removes a value from the cache using the default driver.

If the key doesn't exist, this operation is a no-op.

Throws CacheException if the key is empty or if the operation fails.

Implementation

@override
Future<void> forget(String key) async {
  _validator.validateKey(key);

  try {
    final driver = _driverRegistry.getDefaultDriver();
    await driver.forget(key);
    _statisticsManager.updateStats(
      _driverRegistry.getDefaultDriverName(),
      hit: false,
      operation: 'forget',
    );

    // Remove tags for this key
    _tagManager.removeTagsForKey(key);
  } catch (e) {
    _statisticsManager.updateStats(
      _driverRegistry.getDefaultDriverName(),
      hit: false,
      operation: 'forget',
      error: true,
    );
    throw CacheException('Failed to remove cache item "$key": $e');
  }
}