dotnet / dotnet/extensions

[API Proposal]: Allow to invalidate only local storage via `HybridCache.RemoveAsync`

Open
#5,828 2 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-caching-hybrid
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Background and motivation

Currently it is impossible to invalidate only local cache without rewriting the value via `HybridCache.SetAsync`. `HybridCache.RemoveAsync` will remove entry from both local and remote cache.

The main usage would be to provide user defined workaround until https://github.com/dotnet/extensions/issues/5517 is designed and implemented and/or lazy approach for invalidation.

### API Proposal

```csharp
public enum HybridCacheRemoveMode
{
Full = 0,
LocalOnly = 1
}
```
And extend corresponding methods with it^
```c#
public class HybridCache
{
public abstract ValueTask RemoveAsync(string key, HybridCacheRemoveMode mode = default, CancellationToken cancellationToken = default);
// ....
}
```

### API Usage

```csharp
HybridCache hc = ...;
await hc.RemoveAsync("key", HybridCacheRemoveMode.LocalOnly);
```

### Alternative Designs

_No response_

### Risks

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.