예제 #1
0
        /// <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);
                }
            }
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
 /// <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));
 }
예제 #5
0
 /// <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)));
 }
예제 #6
0
 /// <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)));
 }
예제 #7
0
 /// <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)));
 }
예제 #8
0
        /// <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));
        }