/// <summary> /// Returns Attribute object from cache. If attribute does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id">The id of the Attribute to read</param> /// <returns></returns> public static AttributeCache Read(int id) { string cacheKey = AttributeCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; AttributeCache attribute = cache[cacheKey] as AttributeCache; if (attribute != null) { return(attribute); } else { var attributeService = new Rock.Model.AttributeService(); var attributeModel = attributeService.Get(id); if (attributeModel != null) { attribute = new AttributeCache(attributeModel); cache.Set(cacheKey, attribute, new CacheItemPolicy()); return(attribute); } else { return(null); } } }
/// <summary> /// Adds Attribute model to cache, and returns cached object. /// </summary> /// <param name="attributeModel">The attribute model.</param> /// <param name="qualifiers">The qualifiers.</param> /// <returns></returns> public static AttributeCache Read(Rock.Model.Attribute attributeModel, Dictionary <string, string> qualifiers) { AttributeCache attribute = AttributeCache.CopyModel(attributeModel, qualifiers); string cacheKey = AttributeCache.CacheKey(attributeModel.Id); ObjectCache cache = MemoryCache.Default; cache.Set(cacheKey, attribute, new CacheItemPolicy()); return(attribute); }
/// <summary> /// Adds Attribute model to cache, and returns cached object /// </summary> /// <param name="attributeModel">The attributeModel to cache</param> /// <returns></returns> public static AttributeCache Read(Rock.Model.Attribute attributeModel) { string cacheKey = AttributeCache.CacheKey(attributeModel.Id); ObjectCache cache = MemoryCache.Default; AttributeCache attribute = cache[cacheKey] as AttributeCache; if (attribute != null) { return(attribute); } else { attribute = new AttributeCache(attributeModel); cache.Set(cacheKey, attribute, new CacheItemPolicy()); return(attribute); } }
/// <summary> /// Removes attribute from cache /// </summary> /// <param name="id">The id of the attribute to remove from cache</param> public static void Flush(int id) { FlushCache(AttributeCache.CacheKey(id)); }
/// <summary> /// Adds Attribute model to cache, and returns cached object. /// </summary> /// <param name="attributeModel">The attribute model.</param> /// <param name="qualifiers">The qualifiers.</param> /// <returns></returns> public static AttributeCache Read(Rock.Model.Attribute attributeModel, Dictionary <string, string> qualifiers) { return(GetOrAddExisting(AttributeCache.CacheKey(attributeModel.Id), () => LoadByModel(attributeModel, qualifiers))); }
/// <summary> /// Adds Attribute model to cache, and returns cached object /// </summary> /// <param name="attributeModel">The attributeModel to cache</param> /// <returns></returns> public static AttributeCache Read(Rock.Model.Attribute attributeModel) { return(GetOrAddExisting(AttributeCache.CacheKey(attributeModel.Id), () => LoadByModel(attributeModel))); }
/// <summary> /// Returns Attribute object from cache. If attribute does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id">The id of the Attribute to read</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> public static AttributeCache Read(int id, RockContext rockContext = null) { return(GetOrAddExisting(AttributeCache.CacheKey(id), () => LoadById(id, rockContext))); }
/// <summary> /// Removes attribute from cache /// </summary> /// <param name="id">The id of the attribute to remove from cache</param> public static void Flush(int id) { ObjectCache cache = MemoryCache.Default; cache.Remove(AttributeCache.CacheKey(id)); }