Example #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);
                }
            }
        }
Example #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);
        }
Example #3
0
        /// <summary>
        /// Retrieves an item from the current HTTPRequest items collection.  This is useful to retrieve an object
        /// that was saved by a previous block on the same page.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public object GetSharedItem(string key)
        {
            string itemKey = string.Format("{0}:Item:{1}", Page.CacheKey(Id), key);

            System.Collections.IDictionary items = HttpContext.Current.Items;
            if (items.Contains(itemKey))
            {
                return(items[itemKey]);
            }

            return(null);
        }
Example #4
0
        /// <summary>
        /// Used to save an item to the current HTTPRequests items collection.  This is useful if multiple blocks
        /// on the same page will need access to the same object.  The first block can read the object and save
        /// it using this method for the other blocks to reference
        /// </summary>
        /// <param name="key"></param>
        /// <param name="item"></param>
        public void SaveSharedItem(string key, object item)
        {
            string itemKey = string.Format("{0}:Item:{1}", Page.CacheKey(Id), key);

            System.Collections.IDictionary items = HttpContext.Current.Items;
            if (items.Contains(itemKey))
            {
                items[itemKey] = item;
            }
            else
            {
                items.Add(itemKey, item);
            }
        }
Example #5
0
        /// <summary>
        /// Removes page from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(Page.CacheKey(id));
        }