-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
V15: Hybrid Caching #16938
Merged
Merged
V15: Hybrid Caching #16938
+5,881
−132
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: Elitsa Marinovska <[email protected]>
Co-authored-by: Ronald Barendse <[email protected]>
Loading status checks…
…into v15/feature/update-to-dotnet-9
nikcio
reviewed
Aug 29, 2024
src/Umbraco.PublishedCache.HybridCache/Persistence/ContentSourceDto.cs
Outdated
Show resolved
Hide resolved
Loading status checks…
…-caching
Loading status checks…
… deleted
Loading status checks…
…eature/hybrid-caching
Merged
Will this change also affect Isolated caches? Will they become distributed if L2 cache will be configured? |
No, there has been no change in this regard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hybrid Caching
This PR introduces new hybrid cache implementations of the cache interfaces,
If you want to learn more about what hybrid caching is, read: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/hybrid?view=aspnetcore-9.0
Second level cache
For how to implement a secondary cache with this, see: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-9.0#distributed-redis-cache
Additions to the cache interfaces
IPublishedMemberCache
IPublishedMediaCache
IPublishedContentCache
And with this PR, we add some async methods to these. This way we break less code, but we can also modernize with some async methods.
What happened to PublishedSnapshot?
With nucache, we had a concept of a
PublishedSnapshot
, this was a cache snapshot, so that you would have the same entities during a request, so that if anything got changed /deleted during your request, that would not interfere / cause errors.This is no longer a thing with the Hybrid Cache, as it has no concept of cache snapshots.
This also means that
IPublishedSnapshot
,IPublishedSnapshotAccessor
&SnapshotCache
is all obsolete.And even the
PropertyCacheLevel.Snapshot
is also obsolete.The Hybrid Cache project
Cache implementations
The cache implementations instead of having tons of logic inside them, now calls the cache service instead to get out items.
Note that theres a lot of not implemented methods here, as they are all obsolete, and no longer part of this caching.
Thus they will have to be removed when we remove NuCache.
What Caches do we have now then?
PropertyCacheLevel.Elements
The cache services
These cache services that the caches use, now use the new snazzy dotnet 9 feature
HybridCache
.Cache service responsibility includes:
IPublishedContent
PublishedContent changes
PublishedContent no longer has any Tree logic, this means, we no longer have children / parent.
PublishedProperty
The big change to PublishedProperty is that we no longer use snapshots, so in the
GetCacheValues
method, we can avoid using snapshot, and instead just fall back to theElement
behavior.Seeding
So for NuCache, it would load everything into memory, this is really performant when everything is finally loaded in. But causes issues like :
So we have strayed from this approach with this. We do however recognize that sometimes you might want to have some pages always in memory (stuff like the front page), this is where the seeding feature comes in.
You can now instead deine a list of content type ids in
appsettings.json
, which in turn will load every document that uses the given document types, into the cache, and will never evict them.This new setting can be set like:
Features still missing
How to test
Note: We can't do a full proper tests before we can replace NuCache. And we can only replace NuCache once this and #16818 is merged 😁
For now we can instead test this with trying out some distributed cache implementation, and asserting entities actually are in the cache, both after getting the entity, but also seeding.
We will now use the SqlServer distributed cache, you can directly follow the documentation here: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-8.0#distributed-sql-server-cache
It would also be nice to tests this with other implementations of this, like Redis.
(localdb)\MSSQLLocalDB
and created a database calledDistCache
dotnet sql-cache create "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DistCache;Integrated Security=True;" dbo TestCache
Microsoft.Extensions.Caching.SqlServer
to the Web.UI projectprogram.cs
, paste this on line 2:dbo.TestCache
table, this should now contain 1 entry, and that should be your content you created with the "RootSeed" contentype,https://localhost:44339/My
)