Skip to content

Commit 693d51d

Browse files
authored
Merge pull request #35379 from mgravell/marc/hc_sec
HybridCache - Additional notes on key and tag usage
2 parents 7cdd284 + f9cfb7a commit 693d51d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

aspnetcore/performance/caching/hybrid.md

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

8787
* 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.
8888
* Keys must be valid Unicode sequences. If invalid Unicode sequences are passed, the behavior is undefined.
89-
* 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.
89+
* When using an out-of-process secondary cache such as `IDistributedCache`, the 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 or alias attacks (using bitwise string equality). However, this scenario might still result in conflicting keys becoming overwritten or evicted sooner than expected.
9090

9191
### The alternative `GetOrCreateAsync` overload
9292

@@ -117,7 +117,16 @@ Set tags when calling `GetOrCreateAsync`, as shown in the following example:
117117

118118
Remove all entries for a specified tag by calling <xref:Microsoft.Extensions.Caching.Hybrid.HybridCache.RemoveByTagAsync%2A> with the tag value. An overload lets you specify a collection of tag values.
119119

120-
When an entry is removed, it is removed from both the primary and secondary caches.
120+
Neither `IMemoryCache` nor `IDistributedCache` has direct support for the concept of tags, so tag-based invalidation 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.
121+
122+
## Removing all cache entries
123+
124+
The asterisk 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 continue to exist until they expire naturally. Glob-style matches are not supported. For example, you can't use `RemoveByTagAsync("foo*")` to remove everything starting with `foo`.
125+
126+
### Additional tag considerations
127+
128+
* The system doesn't limit the number of tags you can use, but large sets of tags might negatively impact performance.
129+
* Tags can't be empty, just whitespace, or the reserved value `*`.
121130

122131
## Options
123132

0 commit comments

Comments
 (0)