예제 #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
            {
                Rock.Model.AttributeService attributeService = new Rock.Model.AttributeService();
                Rock.Model.Attribute        attributeModel   = attributeService.Get(id);
                if (attributeModel != null)
                {
                    attribute = AttributeCache.CopyModel(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 = AttributeCache.CopyModel(attributeModel);
                cache.Set(cacheKey, attribute, new CacheItemPolicy());

                return(attribute);
            }
        }