コード例 #1
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static CategoryCache Read(Guid guid)
        {
            ObjectCache cache    = MemoryCache.Default;
            object      cacheObj = cache[guid.ToString()];

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var categoryService = new CategoryService();
                var categoryModel   = categoryService.Get(guid);

                if (categoryModel != null)
                {
                    categoryModel.LoadAttributes();
                    var category = new CategoryCache(categoryModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(CategoryCache.CacheKey(category.Id), category, cachePolicy);
                    cache.Set(category.Guid.ToString(), category.Id, cachePolicy);

                    return(category);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns Category object from cache.  If category does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id of the Category to read</param>
        /// <returns></returns>
        public static CategoryCache Read(int id)
        {
            string cacheKey = CategoryCache.CacheKey(id);

            ObjectCache   cache    = MemoryCache.Default;
            CategoryCache category = cache[cacheKey] as CategoryCache;

            if (category != null)
            {
                return(category);
            }
            else
            {
                var categoryService = new Rock.Model.CategoryService();
                var categoryModel   = categoryService.Get(id);
                if (categoryModel != null)
                {
                    category = new CategoryCache(categoryModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(cacheKey, category, cachePolicy);
                    cache.Set(category.Guid.ToString(), category.Id, cachePolicy);

                    return(category);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #3
0
ファイル: CategoryCache.cs プロジェクト: timothybaloyi/Rock
 /// <summary>
 /// Removes category from cache
 /// </summary>
 /// <param name="id">The id of the category to remove from cache</param>
 public static void Flush(int id)
 {
     FlushCache(CategoryCache.CacheKey(id));
 }
コード例 #4
0
ファイル: CategoryCache.cs プロジェクト: timothybaloyi/Rock
 /// <summary>
 /// Adds Category model to cache, and returns cached object
 /// </summary>
 /// <param name="categoryModel">The categoryModel to cache</param>
 /// <returns></returns>
 public static CategoryCache Read(Rock.Model.Category categoryModel)
 {
     return(GetOrAddExisting(CategoryCache.CacheKey(categoryModel.Id),
                             () => LoadByModel(categoryModel)));
 }
コード例 #5
0
ファイル: CategoryCache.cs プロジェクト: timothybaloyi/Rock
 /// <summary>
 /// Returns Category object from cache.  If category does not already exist in cache, it
 /// will be read and added to cache
 /// </summary>
 /// <param name="id">The id of the Category to read</param>
 /// <param name="rockContext">The rock context.</param>
 /// <returns></returns>
 public static CategoryCache Read(int id, RockContext rockContext = null)
 {
     return(GetOrAddExisting(CategoryCache.CacheKey(id),
                             () => LoadById(id, rockContext)));
 }
コード例 #6
0
        /// <summary>
        /// Removes category from cache
        /// </summary>
        /// <param name="id">The id of the category to remove from cache</param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

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