-
Notifications
You must be signed in to change notification settings - Fork 803
Added docs around IMemberPartialViewCacheInvalidator #7133
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
Changes from 2 commits
87efc58
da2192f
ab385da
a40939d
216b0b4
4a948d2
5f6d278
3d0cc01
bbf9c18
97ceb8d
6119a07
c7175d0
837ec7d
e90fc5c
333086a
6ee05bf
c7b5fd1
39386f5
2b04589
14f0e0e
c8e41bc
c315ff6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Partial view cache refresher for members | ||
|
||
This section describes the `IMemberPartialViewCacheInvalidator` interface, what it's default implementation does and how to customize it. | ||
|
||
## What is an IMemberPartialViewCacheInvalidator? | ||
|
||
This interface is used to isolate the logic that invalidates parts of the partial view cache when a member is updated. | ||
|
||
## Why do we need to partially invalidate the partial view cache? | ||
|
||
Razor templates showing data retrieved from a member object can be cached as partial views via: | ||
|
||
|
||
## Where is it used? | ||
|
||
This interface is called from the member cache refresher (`MemberCacheRefresher`) which is invoked every time a member is updated. | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Details of the default implementation | ||
|
||
Razor template partials are cached through a call to `Html.CachedPartialAsync` with `cacheByMember` set to `true`. This will append the id of the currently logged in member with a marker to the partial view cache key. For example, `-m1015-`. | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
When the `ClearPartialViewCacheItems` method is called it will clear all cache items that match the marker for the updated members. | ||
|
||
Since it is possible to call the `Html.CachedPartialAsync` with `cacheByMember` set to `true` while there is no member logged in, it will also clear all cache items with an empty member marker (i.e. `-m-`) | ||
Check warning on line 24 in 13/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md
|
||
Migaroez marked this conversation as resolved.
Show resolved
Hide resolved
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Customizing the implementation | ||
|
||
You can replace the default implementation by removing it and registering your own in a composer. | ||
|
||
```csharp | ||
public class ReplaceMemberCacheInvalidatorComposer : IComposer | ||
{ | ||
public void Compose(IUmbracoBuilder builder) | ||
{ | ||
builder.Services.AddUnique<IMemberPartialViewCacheInvalidator, MyCustomMemberPartialViewCacheInvalidator>(); | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# ICacheRefresher | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This section describes what IMemberPartialViewCacheInvalidator is, what it's default implementation does and how to customize it. | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## What is an IMemberPartialViewCacheInvalidator | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This interface is used to isolate the logic that needs to run to invalidate parts of the PartialView cache when a member is updated | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Why do we need to partialy invalidate the partialView cache | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Since some of the razor templates might show data that is retrieved from a member object and those templates might be cached by using the partial caching mechanism (i.e. `@await Html.CachedPartialAsync("member",Model,TimeSpan.FromDays(1), cacheByMember:true)`), we need to remove those cached partials when a member is updated. | ||
Check warning on line 11 in 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md
|
||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Where is it used | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This interface is called from the MemberCacheRefresher which is called every time a member is updated. | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Details of the implementation | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
When a razor template partial is cached trough `Html.CachedPartialAsync` and `cacheByMember` is set to `true`, the extension method will append the memberId of the currently logged in member and a marker (i.e. `-m1015-`) to the partialView chachekey. | ||
Check warning on line 19 in 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md
|
||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
When the `ClearPartialViewCacheItems` method is called it will clear all PartialView cacheItems that have the memberId marker for all passed in members. | ||
Since it is possible to call the `Html.CachedPartialAsync` with `cacheByMember` set to `true` while there is no member logged in, it will also clear all cache items with an empty member marker (i.e. `-m-`) | ||
Check warning on line 21 in 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md
|
||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Customizing the implementation | ||
|
||
You can replace the default implementation like usual by removing the default and registering your own in a composer. | ||
eshanrnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```csharp | ||
public class ReplaceMemberCacheInvalidatorComposer : IComposer | ||
{ | ||
public void Compose(IUmbracoBuilder builder) | ||
{ | ||
builder.Services.AddUnique<IMemberPartialViewCacheInvalidator, MyCustomMemberPartialViewCacheInvalidator>(); | ||
} | ||
} | ||
``` |
Uh oh!
There was an error while loading. Please reload this page.