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
Dynamic cache #1624
Dynamic cache #1624
Conversation
…dynamic_cache # Conflicts: # src/OrchardCore.Modules/OrchardCore.DynamicCache/Services/DynamicCacheShapeDisplayEvents.cs
… nested within each other
Updates documentation
…dynamic_cache # Conflicts: # src/OrchardCore.Themes/TheBlogTheme/Views/Menu.liquid
Liquid cache statement gracefully handles no available cache service
Adds liquid tags to alter current CacheContext
|
||
| Method | Description | | ||
| --------- | ----------- | | ||
| `During(Timespan)` | Cached the shape for the specific amount of time. | | ||
| `WithDuration(Timespan)` | Cache the shape for the specific amount of time. | | ||
| `WithSlidingExpiration(Timespan)` | Cache the shape for a specific amount of time with a sliding window. | | ||
| `AddContext(params string[])` | Varies the cached content on the specified context values. | | ||
| `RemoveContext(string)` | Removes the specified context. | | ||
| `AddDependency(params string[])` | Defines the context values that will invalidate the cache entry. | |
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.
here
@@ -1,5 +1,5 @@ | |||
{% cache "blog-post-summary" %} | |||
{% cache Model.ContentItem.ContentItemId %} | |||
{% assign cacheId = "blog-post-summary-" | append: Model.ContentItem.ContentItemId %} |
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.
Why both in the id
and as a dependency?
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 dependency causes the cached block to be invalidated when the content changes.
The cache id gives us a unique cache item for each blog post.
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.
But you pass an id, not a content item to the dependency. How does it know it's a content item id?
Task SetCachedValueAsync(CacheContext context, string value); | ||
Task<string> ProcessEdgeSideIncludesAsync(string value); | ||
Task SetCachedValueAsync(CacheContext context, string value); | ||
Task<string> ReplaceEdgeSideIncludeTokensAsync(string value); |
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.
All the calls to ReplaceEdgeSideIncludeTokensAsync
have been removed?
Other small tidyups for PR
// So, if the cache context is not present in the _cached collection, we need to insert the ChildContent value into the cache: | ||
if (!_cached.Contains(cacheContext) && context.ChildContent != null) | ||
{ | ||
_cacheScopeManager.ExitScope(); // todo: how can we guarantee that this is called, even on failures? |
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.
^^ Any suggestions on how to achieve this?
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.
We need another method that will be called when the display failed, or that is called even if it failed. I am checking where IShapeDisplayEvents
is called.
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.
We can also implement IDisposable
and call dispose on the event instances from the caller. Is it didn't go into DisplayedAsync
but calls Dispose
then we know there was an issue and can exit from the scope.
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.
Make IShapeDisplayEvents
implement IDisposable
? I don't think this would work as these scopes are sensitive to the order that they are opened and closed, so you'd need a new instance of each IShapeDisplayEvents
for every shape (so that they could be disposed immediately after each shape had been rendered).
I think the first suggestion could work though.
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.
ok
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.
Looks like shape events are only used in one place - DefaultHtmlDisplay
.
Suggest adding Task DisplayingFailedAsync(ShapeDisplayContext context);
to interface, and we guarantee that one of DisplayingFailedAsync or DisplayedAsync is always called.
Removes testing markup from views
return Completion.Normal; | ||
} | ||
|
||
cacheScopeManager.EnterScope(cacheContext); |
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.
try/finally to ensure ExitScope
is always called
// So, if the cache context is not present in the _cached collection, we need to insert the ChildContent value into the cache: | ||
if (!_cached.Contains(cacheContext) && context.ChildContent != null) | ||
{ | ||
_cacheScopeManager.ExitScope(); // todo: how can we guarantee that this is called, even on failures? |
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.
We can also implement IDisposable
and call dispose on the event instances from the caller. Is it didn't go into DisplayedAsync
but calls Dispose
then we know there was an issue and can exit from the scope.
Fixes cache attribute name on menu tag Adds DisplayingFinalizedAsync to shape disply
…dynamic_cache # Conflicts: # src/OrchardCore.Themes/TheBlogTheme/Views/Content-BlogPost.Summary.liquid
} | ||
|
||
var debugMode = Configuration.IsDebugModeEnabled; | ||
var splitChars = new[] { ',', ' ' }; |
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.
static
For #1569
There's still a few things to do, but I'd like to get feedback on progress so far.
To do:
cache
block is registered inliquid
at the moment, this probably isn't right.