forget method
Removes a value from the cache by its key.
Deletes the cached item associated with the key if it exists.
If the key does not exist, this operation should be a no-op (no exception thrown).
Throws an exception if the key is null or empty.
- Parameters:
key: A non-null, non-empty string representing the cache key.
Implementation
@override
Future<void> forget(String key) async {
if (key.isEmpty) {
throw ArgumentError('Cache key cannot be empty');
}
try {
final deleted = await _executeCommand(['DEL', key]);
if (deleted is int && deleted > 0) {
_stats.deletions++;
}
} catch (e) {
throw CacheException('Failed to remove cache item "$key": $e');
}
}