/// <summary> /// Flushes a cached page and it's parent page's list of child pages whenever a page is updated /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.ModelUpdatedEventArgs"/> instance containing the event data.</param> void Page_Updated(object sender, Rock.Data.ModelUpdatedEventArgs e) { // Get a reference to the updated page Rock.Model.Page page = e.Model as Rock.Model.Page; if (page != null) { // Check to see if the page being updated is cached System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default; if (cache.Contains(Rock.Web.Cache.PageCache.CacheKey(page.Id))) { // Get the cached page var cachedPage = Rock.Web.Cache.PageCache.Read(page.Id); // if the parent page has changed, flush the old parent page's list of child pages if (cachedPage.ParentPage != null && cachedPage.ParentPage.Id != page.ParentPageId) { cachedPage.ParentPage.FlushChildPages(); } // Flush the updated page from cache Rock.Web.Cache.PageCache.Flush(page.Id); } // Check to see if updated page has a parent if (page.ParentPageId.HasValue) { // If the parent page is cached, flush it's list of child pages if (cache.Contains(Rock.Web.Cache.PageCache.CacheKey(page.ParentPageId.Value))) { Rock.Web.Cache.PageCache.Read(page.ParentPageId.Value).FlushChildPages(); } } } }
/// <summary> /// Flushes a block and it's parent page from cache whenever it is updated /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.ModelUpdatedEventArgs"/> instance containing the event data.</param> void Block_Updated(object sender, Rock.Data.ModelUpdatedEventArgs e) { // Get a reference to the update block instance Rock.Model.Block block = e.Model as Rock.Model.Block; if (block != null) { // Flush the block instance from cache Rock.Web.Cache.BlockCache.Flush(block.Id); // Flush the block instance's parent page if (block.PageId.HasValue) { Rock.Web.Cache.PageCache.Flush(block.PageId.Value); } } }