Ejemplo n.º 1
0
        /// <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.CMS.Page page = e.Model as Rock.CMS.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.Page.CacheKey(page.Id)))
                {
                    // Get the cached page
                    var cachedPage = Rock.Web.Cache.Page.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.Page.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.Page.CacheKey(page.ParentPageId.Value)))
                    {
                        Rock.Web.Cache.Page.Read(page.ParentPageId.Value).FlushChildPages();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns Page object from cache.  If page does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Page Read(int id)
        {
            string cacheKey = Page.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            Page        page  = cache[cacheKey] as Page;

            if (page != null)
            {
                return(page);
            }
            else
            {
                Rock.CMS.PageService pageService = new CMS.PageService();
                Rock.CMS.Page        pageModel   = pageService.Get(id);
                if (pageModel != null)
                {
                    Rock.Attribute.Helper.LoadAttributes(pageModel);

                    page = Page.CopyModel(pageModel);

                    cache.Set(cacheKey, page, new CacheItemPolicy());

                    return(page);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds Page model to cache, and returns cached object
        /// </summary>
        /// <param name="pageModel"></param>
        /// <returns></returns>
        public static Page Read(Rock.CMS.Page pageModel)
        {
            Page page = Page.CopyModel(pageModel);

            string      cacheKey = Page.CacheKey(pageModel.Id);
            ObjectCache cache    = MemoryCache.Default;

            cache.Set(cacheKey, page, new CacheItemPolicy());

            return(page);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Saves the attribute values for the page
 /// </summary>
 /// <param name="personId">The person id.</param>
 public void SaveAttributeValues(int?personId)
 {
     Rock.CMS.PageService pageService = new CMS.PageService();
     Rock.CMS.Page        pageModel   = pageService.Get(this.Id);
     if (pageModel != null)
     {
         Rock.Attribute.Helper.LoadAttributes(pageModel);
         foreach (var category in pageModel.Attributes)
         {
             foreach (var attribute in category.Value)
             {
                 Rock.Attribute.Helper.SaveAttributeValues(pageModel, attribute, this.AttributeValues[attribute.Key].Value, personId);
             }
         }
     }
 }
Ejemplo n.º 5
0
        // Copies the Model object to the Cached object
        private static Page CopyModel(Rock.CMS.Page pageModel)
        {
            Page page = new Page();

            page.Id                     = pageModel.Id;
            page.ParentPageId           = pageModel.ParentPageId;
            page.SiteId                 = pageModel.SiteId;
            page.Layout                 = pageModel.Layout;
            page.Order                  = pageModel.Order;
            page.OutputCacheDuration    = pageModel.OutputCacheDuration;
            page.Name                   = pageModel.Name;
            page.Description            = pageModel.Description;
            page.IconUrl                = pageModel.IconUrl;
            page.AttributeValues        = pageModel.AttributeValues;
            page.IncludeAdminFooter     = pageModel.IncludeAdminFooter;
            page.Title                  = pageModel.Title;
            page.DisplayInNavWhen       = pageModel.DisplayInNavWhen;
            page.MenuDisplayChildPages  = pageModel.MenuDisplayChildPages;
            page.MenuDisplayDescription = pageModel.MenuDisplayDescription;
            page.MenuDisplayIcon        = pageModel.MenuDisplayIcon;
            page.EnableViewstate        = pageModel.EnableViewState;
            page.RequiresEncryption     = pageModel.RequiresEncryption;

            if (pageModel.Attributes != null)
            {
                foreach (var category in pageModel.Attributes)
                {
                    foreach (var attribute in category.Value)
                    {
                        page.AttributeIds.Add(attribute.Id);
                    }
                }
            }

            page.AuthEntity       = pageModel.AuthEntity;
            page.SupportedActions = pageModel.SupportedActions;

            return(page);
        }
Ejemplo n.º 6
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.CMS.Page page = e.Model as Rock.CMS.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.Page.CacheKey(page.Id)))
                {
                    // Get the cached page
                    var cachedPage = Rock.Web.Cache.Page.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.Page.Flush(page.Id);
                }
            }
        }