Пример #1
0
 /// <summary>
 /// 取得缓存的对象,按配置中的Cache_TimeoutMinutes缓存
 /// </summary>
 /// <typeparam name="TT"></typeparam>
 /// <param name="cacheKey"></param>
 /// <param name="syncLock"></param>
 /// <param name="getCacheItem"></param>
 /// <returns></returns>
 public static TT GetCacheItem <TT>(string cacheKey, object syncLock, GetCacheItemDelegate <TT> getCacheItem)
 {
     return(GetCacheItem <TT>(cacheKey,
                              syncLock,
                              CacheItemPriority.Normal,
                              null,
                              null,
                              TimeSpan.FromMinutes(m_CacheTimeoutMinutes),
                              getCacheItem));
 }
Пример #2
0
 /// <summary>
 /// 缓存对象
 /// </summary>
 /// <typeparam name="TT"></typeparam>
 /// <param name="cacheKey"></param>
 /// <param name="syncLock"></param>
 /// <param name="cacheDependencyFileName">缓存依赖的文件</param>
 /// <param name="getCacheItem"></param>
 /// <returns></returns>
 public static TT GetCacheItem <TT>(string cacheKey, object syncLock, string cacheDependencyFileName,
                                    GetCacheItemDelegate <TT> getCacheItem)
 {
     return(GetCacheItem <TT>(cacheKey,
                              syncLock,
                              CacheItemPriority.Normal,
                              null,
                              new CacheDependency(cacheDependencyFileName),
                              TimeSpan.FromHours(1),
                              getCacheItem));
 }
Пример #3
0
        /// <summary>
        /// Gets the cache item.
        /// </summary>
        /// <typeparam name="TCacheItem">The type of the T.</typeparam>
        /// <param name="cacheKey">The cache key.</param>
        /// <param name="syncLock">The sync lock.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="refreshAction">The refresh action.</param>
        /// <param name="cacheDependency">The cache dependency.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="getCacheItem">The get cache item.</param>
        /// <returns></returns>
        public static TCacheItem GetCacheItem <TCacheItem>(string cacheKey, object syncLock,
                                                           CacheItemPriority priority, CacheItemRemovedCallback refreshAction,
                                                           CacheDependency cacheDependency, TimeSpan timeout,
                                                           GetCacheItemDelegate <TCacheItem> getCacheItem)
        {
            object result = HttpRuntime.Cache.Get(cacheKey);

            if (result == null)
            {
                lock (syncLock)
                {
                    result = HttpRuntime.Cache.Get(cacheKey);
                    if (result == null)
                    {
                        result = getCacheItem();
                        HttpRuntime.Cache.Add(cacheKey, result, cacheDependency,
                                              DateTime.Now.Add(timeout), TimeSpan.Zero, priority, refreshAction);
                    }
                }
            }
            return((TCacheItem)result);
        }
Пример #4
0
 public static TT GetCacheItem <TT>(string cacheKey, object syncLock,
                                    TimeSpan timeout, GetCacheItemDelegate <TT> getCacheItem)
 {
     return(GetCacheItem(cacheKey, syncLock, null, timeout, getCacheItem));
 }
Пример #5
0
        public static TT GetCacheItem <TT>(string cacheKey, object syncLock,
                                           CacheItemPriority priority, CacheItemRemovedCallback refreshAction,
                                           CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate <TT> getCacheItem)
        {
            var       helper = new CacheHelper(System.Web.HttpRuntime.Cache);
            Func <TT> f      = () => getCacheItem();

            return(helper.GetCacheItem(cacheKey, priority, refreshAction, cacheDependency, timeout, f, syncLock));
        }
Пример #6
0
 public static TT GetCacheItem <TT>(string cacheKey, object syncLock,
                                    CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout,
                                    GetCacheItemDelegate <TT> getCacheItem)
 {
     return(GetCacheItem(cacheKey, syncLock, priority, refreshAction, null, timeout, getCacheItem));
 }