Skip to content

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

Merged
merged 22 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
87efc58
Added docs around IMemberPartialViewCacheInvalidator
Migaroez Jun 2, 2025
da2192f
Apply suggestions from code review
Migaroez Jul 14, 2025
ab385da
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
a40939d
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
216b0b4
Update 13/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
4a948d2
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
5f6d278
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
3d0cc01
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
bbf9c18
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
97ceb8d
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
6119a07
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
c7175d0
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
837ec7d
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
e90fc5c
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
333086a
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
6ee05bf
Update 13/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
c7b5fd1
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
39386f5
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
2b04589
Update 13/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
14f0e0e
Update 16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalida…
eshanrnh Jul 15, 2025
c8e41bc
Merge branch 'main' into new/member-partial-cache
AndyButland Aug 5, 2025
c315ff6
Handled issues raised in review.
AndyButland Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

## 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-`.

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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐢 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "13/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md", "range": {"start": {"line": 24, "column": 1}}}, "severity": "WARNING"}

## 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

This section describes what IMemberPartialViewCacheInvalidator is, what it's default implementation does and how to customize it.

## What is an IMemberPartialViewCacheInvalidator

This interface is used to isolate the logic that needs to run to invalidate parts of the PartialView cache when a member is updated

## Why do we need to partialy invalidate the partialView cache

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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐢 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md", "range": {"start": {"line": 11, "column": 1}}}, "severity": "WARNING"}

## Where is it used

This interface is called from the MemberCacheRefresher which is called every time a member is updated.

## Details of the implementation

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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐢 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md", "range": {"start": {"line": 19, "column": 1}}}, "severity": "WARNING"}
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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐢 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "16/umbraco-cms/reference/cache/imemberpartialviewcacheinvalidator.md", "range": {"start": {"line": 21, "column": 1}}}, "severity": "WARNING"}

## Customizing the implementation

You can replace the default implementation like usual by removing the default and registering your own in a composer.

```csharp
public class ReplaceMemberCacheInvalidatorComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddUnique<IMemberPartialViewCacheInvalidator, MyCustomMemberPartialViewCacheInvalidator>();
}
}
```
Loading