Exemplo n.º 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);
        }
Exemplo n.º 2
0
 static RockCacheManager()
 {
     RockCache.AddManager(Instance);
 }