Skip to content

Commit 87efc58

Browse files
committed
Added docs around IMemberPartialViewCacheInvalidator
1 parent 57716e1 commit 87efc58

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ICacheRefresher
2+
3+
This section describes what IMemberPartialViewCacheInvalidator is, what it's default implementation does and how to customize it.
4+
5+
## What is an IMemberPartialViewCacheInvalidator
6+
7+
This interface is used to isolate the logic that needs to run to invalidate parts of the PartialView cache when a member is updated
8+
9+
## Why do we need to partialy invalidate the partialView cache
10+
11+
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.
12+
13+
## Where is it used
14+
15+
This interface is called from the MemberCacheRefresher which is called every time a member is updated.
16+
17+
## Details of the implementation
18+
19+
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.
20+
When the `ClearPartialViewCacheItems` method is called it will clear all PartialView cacheItems that have the memberId marker for all passed in members.
21+
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-`)
22+
23+
## Customizing the implementation
24+
25+
You can replace the default implementation like usual by removing the default and registering your own in a composer.
26+
27+
```csharp
28+
public class ReplaceMemberCacheInvalidatorComposer : IComposer
29+
{
30+
public void Compose(IUmbracoBuilder builder)
31+
{
32+
builder.Services.AddUnique<IMemberPartialViewCacheInvalidator, MyCustomMemberPartialViewCacheInvalidator>();
33+
}
34+
}
35+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ICacheRefresher
2+
3+
This section describes what IMemberPartialViewCacheInvalidator is, what it's default implementation does and how to customize it.
4+
5+
## What is an IMemberPartialViewCacheInvalidator
6+
7+
This interface is used to isolate the logic that needs to run to invalidate parts of the PartialView cache when a member is updated
8+
9+
## Why do we need to partialy invalidate the partialView cache
10+
11+
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.
12+
13+
## Where is it used
14+
15+
This interface is called from the MemberCacheRefresher which is called every time a member is updated.
16+
17+
## Details of the implementation
18+
19+
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.
20+
When the `ClearPartialViewCacheItems` method is called it will clear all PartialView cacheItems that have the memberId marker for all passed in members.
21+
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-`)
22+
23+
## Customizing the implementation
24+
25+
You can replace the default implementation like usual by removing the default and registering your own in a composer.
26+
27+
```csharp
28+
public class ReplaceMemberCacheInvalidatorComposer : IComposer
29+
{
30+
public void Compose(IUmbracoBuilder builder)
31+
{
32+
builder.Services.AddUnique<IMemberPartialViewCacheInvalidator, MyCustomMemberPartialViewCacheInvalidator>();
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)