Esempio n. 1
0
        /// <summary>
        /// Flushes a block and it's parent page from cache whenever it is being deleted
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.ModelUpdatingEventArgs"/> instance containing the event data.</param>
        void Block_Deleting(object sender, Rock.Data.ModelUpdatingEventArgs e)
        {
            // Get a reference to the deleted 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);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Flushes a cached page and it's parent page's list of child pages whenever a page is being deleted
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.ModelUpdatingEventArgs"/> instance containing the event data.</param>
        void Page_Deleting(object sender, Rock.Data.ModelUpdatingEventArgs e)
        {
            // Get a reference to the deleted 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 is not null, flush parent page's list of child pages
                    if (cachedPage.ParentPage != null)
                    {
                        cachedPage.ParentPage.FlushChildPages();
                    }

                    // Flush the updated page from cache
                    Rock.Web.Cache.PageCache.Flush(page.Id);
                }
            }
        }