예제 #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 Attribute Read(int id)
        {
            string cacheKey = Attribute.CacheKey(id);

            ObjectCache cache     = MemoryCache.Default;
            Attribute   attribute = cache[cacheKey] as Attribute;

            if (attribute != null)
            {
                return(attribute);
            }
            else
            {
                Rock.Core.AttributeService attributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute        attributeModel   = attributeService.Get(id);
                if (attributeModel != null)
                {
                    attribute = Attribute.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 attributeModel to cache</param>
        /// <returns></returns>
        public static Attribute Read(Rock.Core.Attribute attributeModel)
        {
            Attribute attribute = Attribute.CopyModel(attributeModel);

            string      cacheKey = Attribute.CacheKey(attributeModel.Id);
            ObjectCache cache    = MemoryCache.Default;

            cache.Set(cacheKey, attribute, new CacheItemPolicy());

            return(attribute);
        }
예제 #3
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(Attribute.CacheKey(id));
        }