Thanks for your reply Anthony... that's a shame, I was hoping you got a bit more luckier in the meanwhile. However, I'm very happy that I can actually clear the cache on publish, makes life a bit easier not having to restart stuff.
I'm going to experiment on this next week... keep you posted.
I think I'll have to setup a second environment, because publishing on my local host (using the same DB) also triggers the cache to be cleared on all sites (~ 10) which causes a CPU spike on production if I'm not careful.
Maybe in the meanwhile one of the Umbraco overlords on this forum reads this thread and goes "Nerds... just add this, et voila"
void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
{
foreach (var entity in e.PublishedEntities)
{
// Clear the cache
}
}
But now I'm stuck clearing a particular cached item.
My idea was to fetch the document type from the published entity, this matches up with my custom controller names.
For example, I have a doctype Tour and a view called Index and a custom controller called TourController.
When doctype Tour is published, I want to call the outputcachemanager and clear the cache for this type. Which could be something like this:
var docType = entity.ContentType;
var view = entity.Template;
// Clear the cache
OutputCacheManager manager = new OutputCacheManager();
manager.RemoveItem(docType, view);
But I cannot get this to work. I also tried doing it hard coded as a test, but the same result, the cache will not clear.
manager.RemoveItem("Tour", "Index");
This does work:
manager.RemoveItems();
But will result in all the cache being cleared of course.
Maybe the problem is with the way I'm caching my controllers? Our umbraco installation hold multiple sites, that's why I'm varying by baseurl to prevent cross-site caching.
Testing is a bit tricky, because of the events on the production env which will clear the cache while developing. I think I'll setup a blank solution with a fresh install and develop this further on there.
I hope this is the right track, I'm still kind of a Umbraco/C# noob because I'm a UX Designer. But hey... I'm learning.
//if the document type alias of the published content item is in the list above then invalidate the cache.
if (e.PublishedEntities.Any(x => navigationDocTypeAliases.Contains(x.ContentType.Alias)))
{
var cacheManager = new OutputCacheManager();
cacheManager.RemoveItem("SiteLayout", "RenderMainNavigation");
}
Clearing the donut cache for a particular page on publish
I have donutcache attributes on the controllers of my website. On the "Content_Published" event i would like to clear the cache for a particular page.
The above would clear the cache for all pages. There are overrides that enable entering a "ControllerName", "ActionName".
Whenever i try to get these. I get Controller "Content", Action "Post_Saved". I'm assuming these are the internal umbraco routes.
I'm interested in recommendations for managing the output cache. Is there a way to save a key and remove the cache via the key.
Yeah, I was wondering about the same actually.
I have multiple websites running and a publish on any of the sites will clear the cache for all pages... and all sites.
It would be really nice to limit the cache refresh to a page/template/nodetype... ? But would this be possible?
Hi Martijn! I still haven't resolved this. There must be a way to configure this.
Thanks for your reply Anthony... that's a shame, I was hoping you got a bit more luckier in the meanwhile. However, I'm very happy that I can actually clear the cache on publish, makes life a bit easier not having to restart stuff.
I'm going to experiment on this next week... keep you posted.
I think I'll have to setup a second environment, because publishing on my local host (using the same DB) also triggers the cache to be cleared on all sites (~ 10) which causes a CPU spike on production if I'm not careful.
Maybe in the meanwhile one of the Umbraco overlords on this forum reads this thread and goes "Nerds... just add this, et voila"
;')
Have a nice weekend.
Hey Anthony,
I'm still busy figuring this out and I think I might be on to something. What i've done so far is the following:
In my app startup, I've added a reference to Umbraco.Core.Services
Then in ApplicationStarting I've hooked into the ContentService:
This references the following code:
But now I'm stuck clearing a particular cached item.
My idea was to fetch the document type from the published entity, this matches up with my custom controller names.
For example, I have a doctype Tour and a view called Index and a custom controller called TourController.
When doctype Tour is published, I want to call the outputcachemanager and clear the cache for this type. Which could be something like this:
But I cannot get this to work. I also tried doing it hard coded as a test, but the same result, the cache will not clear.
This does work:
But will result in all the cache being cleared of course.
Maybe the problem is with the way I'm caching my controllers? Our umbraco installation hold multiple sites, that's why I'm varying by baseurl to prevent cross-site caching.
Testing is a bit tricky, because of the events on the production env which will clear the cache while developing. I think I'll setup a blank solution with a fresh install and develop this further on there.
I hope this is the right track, I'm still kind of a Umbraco/C# noob because I'm a UX Designer. But hey... I'm learning.
Anthony... my man! I've fixed it! Will post a reply with the details soon, gotta release this first!
Hi,
I'm trying to find a solution to the same problem, please can you post the your own idea :)
Hi had a smimilar issue for my site, but came accross this article by paul seal.
https://codeshare.co.uk/blog/how-to-use-donut-caching-in-umbraco-and-mvc/
He does something like this:
var navigationDocTypeAliases = new List
hope this helps
is working on a reply...