In ASP.NET Core, a cache can be made in a Razor template as follows:
<cache expires-after="@TimeSpan.FromSeconds(3600)">
</cache>
I want to be able to clear all caches programmatically, is this possible?
My issue is I am creating the cache for a website and when a user changes content I want to clear all caches as what needs to show on the front end may change. Is this possible?
CodePudding user response:
It's definitely possible. Unsure if you are using "default" Umbraco caching setup or what you've already tried, but I think you can find some guidance here if so: https://our.umbraco.com/documentation/Reference/Cache/ ?
CodePudding user response:
I came across this blog https://carole.dev/blog/using-asp-net-cache-tag-helper-in-umbraco-9/. It shows how we can add the vary-by
parameter to expire cache.
<cache expires-after="@TimeSpan.FromSeconds(3600)" vary-by="@siteNode.Id @settings.UpdateDate">
</cache>
We can test this by updating some content and publishing in Umbraco. Now it will be updated in the cached page as the updated date “vary-by” value has changed, so the cache knows it’s no longer valid.