Skip to content
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

Merged
merged 25 commits into from May 23, 2018
Merged

Dynamic cache #1624

merged 25 commits into from May 23, 2018

Conversation

paynecrl97
Copy link
Member

@paynecrl97 paynecrl97 commented Mar 17, 2018

For #1569

There's still a few things to do, but I'd like to get feedback on progress so far.

To do:

  • Sort out features- what should live where? cache block is registered in liquid at the moment, this probably isn't right.
  • Dependencies- do we need them?
  • Tests
  • Remove changes to views used for testing

paynecrl97 added 5 commits March 17, 2018 19:12
…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. |
Copy link
Member

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 %}
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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);
Copy link
Member

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?

paynecrl97 added 2 commits May 14, 2018 22:47
// 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?
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member Author

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);
Copy link
Member

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?
Copy link
Member

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[] { ',', ' ' };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

@sebastienros sebastienros merged commit 7fb0838 into dev May 23, 2018
@sebastienros sebastienros deleted the dynamic_cache branch May 23, 2018 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants