/// <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) { string cacheKey = CategoryCache.CacheKey(categoryModel.Id); ObjectCache cache = MemoryCache.Default; CategoryCache category = cache[cacheKey] as CategoryCache; if (category != null) { return(category); } else { category = new CategoryCache(categoryModel); var cachePolicy = new CacheItemPolicy(); cache.Set(cacheKey, category, cachePolicy); cache.Set(category.Guid.ToString(), category.Id, cachePolicy); return(category); } }
/// <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)); }
/// <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))); }
/// <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))); }
/// <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)); }
private static void AddAttributeCategory(List <AttributeCategory> attributeCategories, Rock.Web.Cache.CategoryCache category, Rock.Web.Cache.AttributeCache attribute) { AttributeCategory attributeCategory = null; if (category != null) { attributeCategory = attributeCategories.Where(g => g.Category != null && g.Category.Id == category.Id).FirstOrDefault(); } else { attributeCategory = attributeCategories.Where(g => g.Category == null).FirstOrDefault(); } if (attributeCategory == null) { attributeCategory = new AttributeCategory(); attributeCategory.Category = category; attributeCategory.Attributes = new List <Web.Cache.AttributeCache>(); attributeCategories.Add(attributeCategory); } attributeCategory.Attributes.Add(attribute); }