Пример #1
0
        /// <summary>
        /// Returns BlockInstance object from cache.  If blockInstance does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BlockInstance Read(int id)
        {
            string cacheKey = BlockInstance.CacheKey(id);

            ObjectCache   cache         = MemoryCache.Default;
            BlockInstance blockInstance = cache[cacheKey] as BlockInstance;

            if (blockInstance != null)
            {
                return(blockInstance);
            }
            else
            {
                Rock.CMS.BlockInstanceService blockInstanceService = new CMS.BlockInstanceService();
                Rock.CMS.BlockInstance        blockInstanceModel   = blockInstanceService.Get(id);
                if (blockInstanceModel != null)
                {
                    Rock.Attribute.Helper.LoadAttributes(blockInstanceModel);

                    blockInstance = BlockInstance.CopyModel(blockInstanceModel);

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

                    return(blockInstance);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Adds BlockInstance model to cache, and returns cached object
        /// </summary>
        /// <param name="blockInstanceModel"></param>
        /// <returns></returns>
        public static BlockInstance Read(Rock.CMS.BlockInstance blockInstanceModel)
        {
            BlockInstance blockInstance = BlockInstance.CopyModel(blockInstanceModel);

            string      cacheKey = BlockInstance.CacheKey(blockInstanceModel.Id);
            ObjectCache cache    = MemoryCache.Default;

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

            return(blockInstance);
        }
Пример #3
0
        /// <summary>
        /// Removes blockInstance from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

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