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 {
await _executeCommand(['DEL', key], isWrite: true);
_stats.deletions++;
_stats.sets--; // Correct the set count since DEL is not a SET operation
} catch (e) {
throw CacheException('Failed to remove cache item "$key": $e');
}
}