Skip to content

Commit 5f12c20

Browse files
committed
Additional notes on key and tag usage
1 parent 5415186 commit 5f12c20

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

aspnetcore/performance/caching/hybrid.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Notice that the inline interpolated string syntax (`$"..."` in the preceding exa
9494

9595
* Keys can be restricted to valid maximum lengths. For example, the default `HybridCache` implementation (via `AddHybridCache(...)`) restricts keys to 1024 characters by default. That number is configurable via `HybridCacheOptions.MaximumKeyLength`, with longer keys bypassing the cache mechanisms to prevent saturation.
9696
* Keys must be valid Unicode sequences. If invalid Unicode sequences are passed, the behavior is undefined.
97-
* When using an out-of-process secondary cache such as `IDistributedCache`, the specific backend implementation may impose additional restrictions. As a hypothetical example, a particular backend might use case-insensitive key logic. The default `HybridCache` (via `AddHybridCache(...)`) detects this scenario to prevent confusion attacks, however it may still result in conflicting keys becoming overwritten or evicted sooner than expected.
97+
* When using an out-of-process secondary cache such as `IDistributedCache`, the specific backend implementation may impose additional restrictions. As a hypothetical example, a particular backend might use case-insensitive key logic. The default `HybridCache` (via `AddHybridCache(...)`) detects this scenario to prevent confusion/alias attacks (using bitwise string equality), however it may still result in conflicting keys becoming overwritten or evicted sooner than expected.
9898

9999
### The alternative `GetOrCreateAsync` overload
100100

@@ -128,7 +128,17 @@ Set tags when calling `GetOrCreateAsync`, as shown in the following example:
128128

129129
Remove all entries for a specified tag by calling [`RemoveByTagAsync`](https://source.dot.net/#Microsoft.Extensions.Caching.Hybrid/Runtime/HybridCache.cs,c37a54f5e962ab23) with the tag value. An [overload](https://source.dot.net/#Microsoft.Extensions.Caching.Hybrid/Runtime/HybridCache.cs,9efbe8770df53e9c) lets you specify a collection of tag values.
130130

131-
When an entry is removed, it is removed from both the primary and secondary caches.
131+
Note that because neither `IMemoryCache` nor `IDistributedCache` have direct support for the concept of tags (and tag-based invalidation), this is a *logical* operation only; it does not actively remove values from either local or distributed cache. Instead, it ensures that when receiving data with such tags, the data will be treated as a cache-miss from both the local and remote cache. The values will expire from `IMemoryCache` and `IDistributedCache` in the usual way based on the configured lifetime.
132+
133+
## Removing all cache entries
134+
135+
The tag `*` is reserved as a wildcard and is disallowed against individual values. Calling `RemoveByTagAsync("*")` has the effect of invalidating *all* `HybridCache` data, even data that does not have any tags. As with individual tags, this is a *logical* operation, and individual values may continue to exist until they expire naturally. Glob-style matches are not supported (you cannot use `RemoveByTagAsync("foo*)` to remove everything
136+
starting with `"foo"`).
137+
138+
### Additional tag considerations
139+
140+
* The system does not enforce an upper-limit on the number of tags, but excessively large sets of tags may have performance implications
141+
* Tags cannot be empty or just whitespace, and cannot be the reserved value `"*"`
132142

133143
## Options
134144

0 commit comments

Comments
 (0)