Skip to content

Commit c123b4e

Browse files
0xcedjodydonetti
authored andcommitted
Update the Named Caches documentation
Use the new WithCacheKeyPrefixByCacheName() method instead of the deprecated WithCacheKeyPrefix() method in the code samples.
1 parent fed05f2 commit c123b4e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

docs/NamedCaches.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ services.AddFusionCache("Products")
246246
{
247247
opt.Duration = TimeSpan.FromSeconds(20);
248248
})
249-
.WithCacheKeyPrefix()
249+
.WithCacheKeyPrefixByCacheName()
250250
.WithRegisteredSerializer()
251251
.WithRegisteredDistributedCache()
252252
.WithRegisteredBackplane()
@@ -258,7 +258,7 @@ services.AddFusionCache("Customers")
258258
{
259259
opt.Duration = TimeSpan.FromSeconds(30);
260260
})
261-
.WithCacheKeyPrefix()
261+
.WithCacheKeyPrefixByCacheName()
262262
.WithRegisteredSerializer()
263263
.WithRegisteredDistributedCache()
264264
.WithRegisteredBackplane()
@@ -280,11 +280,9 @@ Normally the answer would be yes, but in this case is a resounding _"nope!"_ bec
280280

281281
### 🔑 Cache Key Prefix
282282

283-
In the code above we also added `WithCacheKeyPrefix()`: that tells FusionCache to add a prefix to each cache key we will pass to it, solving the issue automatically.
283+
In the code above we also added `WithCacheKeyPrefixByCacheName()`: that tells FusionCache to add the cache name plus a little `:` separator as a prefix to each cache key we will pass to it, solving the issue automatically.
284284

285-
By default, when no specific prefix is specified, the `CacheName` plus a little `":"` separator will be used.
286-
287-
Of course it can also be specified manually, by simply using the overload `WithCacheKeyPrefix(prefix)`.
285+
Of course it can also be specified manually, by simply using `WithCacheKeyPrefix(prefix)`.
288286

289287
Basically when doing `_productsCache.Set("Foo123", myProduct)` from the example above the actual cache key used in both the underlying memory and distributed cache will be turned from `"Foo123"` to `"Products:Foo123"`, automatically and transparently avoiding any collision between different cache entries from different caches. The transformed cache key will be used consistently throughout the entire flow: memory cache, distributed cache, events, etc.
290288

0 commit comments

Comments
 (0)