예제 #1
0
        /// <summary>
        /// Gets an item from cache, and if not found, executes the itemFactory to create item and add to cache with an expiration timespan.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="itemFactory">The item factory.</param>
        /// <param name="expiration">The expiration.</param>
        /// <returns></returns>
        internal protected static T GetOrAddExisting(string key, Func <T> itemFactory, TimeSpan expiration)
        {
            string qualifiedKey = QualifiedKey(key);

            var value = RockCacheManager <T> .Instance.Cache.Get(qualifiedKey);

            RockCache.UpdateCacheHitMiss(key, value != null);

            if (value != null)
            {
                return(value);
            }

            if (itemFactory == null)
            {
                return(default(T));
            }

            value = itemFactory();
            if (value != null)
            {
                UpdateCacheItem(key, value, expiration);
            }

            return(value);
        }
예제 #2
0
 static RockCacheManager()
 {
     RockCache.AddManager(Instance);
 }