Exemple #1
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);
                }
            }
        }
Exemple #2
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);
        }