Refresh custom cache on Azure together with Umbraco refreshes
Hi,
Small introduction: After a small Q&A on twitter, Stephan asked me to put it continue on our :-)
The conversation so far:
Me: Is it possible to hook into the umbraco SQL based cache updates?
To invalidate custom cache on Azure on (un)publish?
Stephan: Not sure I understand the question... You can hook into cache
refresher events... Is that what you want?
Me: Yeah I guess! So a cache refresh instruction is sent to all nodes
and I'd like to refresh a custom cache too (on Azure). Do you have an
example by any chance? ;-)
Long description:
I'm working on a Web API project based on Umbraco, which will be hosted on Azure.
Some GET endpoint methods got server-side caching applied, based on the ASP.NET Web API CacheOutput package ([CacheOutput(ServerTimeSpan = int.MaxValue)]).
The used cache type is MemoryCacheDefault and I guess on Azure this is a private cache of the server.
So I'm looking for a way to call my cache clearing code whenever something happens in Umbraco, like (un)publishing, which alters the umbraco cache data.
/// <summary>
/// The relation cache refresher.
/// </summary>
internal class RelationCacheRefresher : JsonCacheRefresherBase<RelationCacheRefresher>
{
/// <summary>
/// Gets the id.
/// </summary>
public static Guid Id
{
get
{
return new Guid("7b8053d6-6ff4-46e2-94c0-115055a8a192");
}
}
/// <summary>
/// Gets the unique identifier.
/// </summary>
public override Guid UniqueIdentifier
{
get
{
return Id;
}
}
/// <summary>
/// Gets the name.
/// </summary>
public override string Name
{
get
{
return "Relation Cache Refresher";
}
}
/// <summary>
/// Returns the real instance of the object ('this') for use in strongly typed events
/// </summary>
protected override RelationCacheRefresher Instance
{
get
{
return this;
}
}
}
Thanks Jeroen, I did a quick Google search on JsonCacheRefresherBase to find more information about what it is and I came across this post, where Shannon explains that there's already an event available for exactly this purpose: PageCacheRefresher.CacheUpdated.
Ah ok I thought you already knew about PageCacheRefresher.CacheUpdated and you wanted to have your own version of it. But yes if you're on Azure and you want to update all servers you need to use PageCacheRefresher.CacheUpdated. It's the new ContentService.Published ;-).
Refresh custom cache on Azure together with Umbraco refreshes
Hi,
Small introduction: After a small Q&A on twitter, Stephan asked me to put it continue on our :-) The conversation so far:
Long description:
I'm working on a Web API project based on Umbraco, which will be hosted on Azure.
Some GET endpoint methods got server-side caching applied, based on the ASP.NET Web API CacheOutput package (
[CacheOutput(ServerTimeSpan = int.MaxValue)]
).The used cache type is
MemoryCacheDefault
and I guess on Azure this is a private cache of the server.So I'm looking for a way to call my cache clearing code whenever something happens in Umbraco, like (un)publishing, which alters the umbraco cache data.
Here is an example of a custom refresher:
The refresher:
Call the refresher:
Execute the refresher:
Jeroen
Thanks Jeroen, I did a quick Google search on
JsonCacheRefresherBase
to find more information about what it is and I came across this post, where Shannon explains that there's already an event available for exactly this purpose:PageCacheRefresher.CacheUpdated
.Tried it just now and it works perfectly :-)
Ah ok I thought you already knew about PageCacheRefresher.CacheUpdated and you wanted to have your own version of it. But yes if you're on Azure and you want to update all servers you need to use PageCacheRefresher.CacheUpdated. It's the new ContentService.Published ;-).
Jeroen
is working on a reply...