Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shivani Bhatt 4 posts 24 karma points
    Jun 24, 2015 @ 15:47
    Shivani Bhatt
    0

    Umbraco 7 - Clearing Outputcache when content node is published/deleted

    Hi,

    I am using Umbraco 7.1.9 and have outputcahce enabled on some controllers. I want to know what is the best way to clear cache when a content item is published/deleted.

    I did implement this in ApplicationStarting by extending ContentService.Published but when I do that, a custom backend section that I wrote does not show up on dashboard.

    Thanks,

    Shivani

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 24, 2015 @ 15:55
    Dave Woestenborghs
    1

    Hi,

    It's better to hook in to the cache refresher events. This is also the only way it will ever work on a load balancend environment.

    /// <summary>
    /// The boot manager.
    /// </summary>
    public class BootManager : ApplicationEventHandler
    {
        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            // hook into core cacherefresher to make sure cache get's cleared correctly when in load balanced environment
            PageCacheRefresher.CacheUpdated += (sender, args) => this.ClearCache();            
            MediaCacheRefresher.CacheUpdated += (sender, args) => this.ClearCache();
            DictionaryCacheRefresher.CacheUpdated += (sender, args) => this.ClearCache();
    
            base.ApplicationStarting(umbracoApplication, applicationContext);            
        }
    
        /// <summary>
        /// Clears the runtime cache on all servers
        /// </summary>
        private void ClearCache()
        {            
            OutputCacheManager manager = new OutputCacheManager();
            manager.RemoveItems();
        }
    }
    

    Dave

  • Shivani Bhatt 4 posts 24 karma points
    Jun 24, 2015 @ 18:28
    Shivani Bhatt
    0

    Thanks Dave. This does not clear cache for me and my custom section still does not show still in backend. I followed this example to create custom section.

  • Shivani Bhatt 4 posts 24 karma points
    Jun 26, 2015 @ 18:44
    Shivani Bhatt
    0

    Turns out that tree.config was not being generated properly and that is why custom tree was not showing up. Is this supposed to be auto-generated by Umbraco or explicitly defined by user?

Please Sign in or register to post replies

Write your reply to:

Draft