コード例 #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
ファイル: RockCacheManager.cs プロジェクト: waldo2590/Rock
 static RockCacheManager()
 {
     RockCache.AddManager(Instance);
 }