Replies: 1 comment
|
No. The built-in stampede lock in The implementation keeps in-flight work in an instance field: private readonly ConcurrentDictionary<StampedeKey, StampedeState> _currentOperations = new();and callers in that same process join the matching Consequently, when the L2 entry expires:
var options = new HybridCacheEntryOptions
{
LocalCacheExpiration = TimeSpan.FromMinutes(1),
Expiration = TimeSpan.FromMinutes(10),
};
var value = await cache.GetOrCreateAsync(
key,
factory,
options,
cancellationToken: cancellationToken);Microsoft's documentation describes L1 as separate per server and L2 as the configured If duplicate regeneration across nodes is acceptable, no extra coordination is needed; the factories race and write equivalent values. You can reduce synchronized expirations with per-key expiration jitter. If the factory is expensive or must execute only once globally, add coordination outside
Do not use an unbounded lock, and do not assume a Redis lock alone gives exactly-once semantics during process pauses or network partitions. The underlying operation should still be idempotent when correctness matters. There is a related multi-node caveat for invalidation: removing a key/tag updates the current server and L2, but it does not immediately evict that key from every other server's L1. For strict cross-node freshness, use short L1 lifetimes, versioned keys, or an explicit pub/sub invalidation mechanism. If this answers the question, please mark it as the accepted answer so future readers can distinguish local stampede protection from a distributed lock. |
Uh oh!
There was an error while loading. Please reload this page.
I read the DefaultHybridCache source code , I haven't found how it handles the L2 cache expiration issue across multiple instances.
All reactions