-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Blazor] Support HybridCache backend for persistent component state #62299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Blazor] Support HybridCache backend for persistent component state #62299
Conversation
@@ -74,6 +74,7 @@ | |||
<MicrosoftNETCoreBrowserDebugHostTransportVersion>10.0.0-preview.6.25304.106</MicrosoftNETCoreBrowserDebugHostTransportVersion> | |||
<MicrosoftExtensionsCachingAbstractionsVersion>10.0.0-preview.6.25304.106</MicrosoftExtensionsCachingAbstractionsVersion> | |||
<MicrosoftExtensionsCachingMemoryVersion>10.0.0-preview.6.25304.106</MicrosoftExtensionsCachingMemoryVersion> | |||
<MicrosoftExtensionsCachingHybridVersion>10.0.0-alpha.2.24462.2</MicrosoftExtensionsCachingHybridVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @sebastienros
private static readonly Func<CancellationToken, ValueTask<PersistedCircuitState>> _failOnCreate = | ||
static ct => throw new InvalidOperationException(); | ||
|
||
private static readonly string[] _tags = ["Microsoft.AspNetCore.Components.Server.PersistedCircuitState"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the primary use of tags is for remove-by-tags-async, but I don't see that used; is this forward thinking to when that might be needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is about making sure that we are "good citizens" of the shared cache and that people have a way of specifically cleaning these entries. Is this the pattern or should I do it in a different way?
{ | ||
await _lock.WaitAsync(cancellation); | ||
var state = await _hybridCache.GetOrCreateAsync( | ||
circuitId.Secret, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know a lot about "circuitid", but: is this unique enough vs other potential parallel HC uses? there may be some benefit in a key prefix, and if you do that, I strongly recommend using interpolated string literals, i.e. $"circuits/{circuitId.Secret}"
, because that should start benefitting from zero-alloc paths in .NET 10 (i.e. for cache hits, it doesn't actually allocate a string
for the composed value, via voodoo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: and then I see that this is only used in the "we need to remove it" case, in which case: you will need the string
, but: just to say, there may still be value in other cases....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the circuit id is 32 bytes of entropy so no chance we hit that :)
f17b908
to
8582da8
Compare
5523b8b
to
963076a
Compare
e5a076c
to
b6632dd
Compare
963076a
to
bddbfd4
Compare
bddbfd4
to
46ebb2c
Compare
src/Components/Server/src/Circuits/HybridCacheCircuitPersistenceProvider.cs
Outdated
Show resolved
Hide resolved
…62299) * Adds support for HybridCache as a backend for persisting component state. * The implementation automatically switches to use HybridCache if one is registered on DI. * A custom HybridCache instance can be set in options for full control over the limits.
HybridCache
as a backend for persisting component state.HybridCache
if one is registered on DI.HybridCache
instance can be set in options for full control over the limits.