Esempio n. 1
0
        /// <summary>
        /// 获取缓存中的本地数据,如果缓存中缺少数据,则回调RecallDataFromLocal事件的数据
        /// </summary>
        /// <returns></returns>
        public static List <T> GetCacheList <T>(this IServiceXCache pInterface, RecallDataFromLocal <T> pdelegate, ICacheConfig pCacheConfig, CacheItemRemovedCallback RemovedCallback)
        {
            object objValue = GetCache(pInterface, pCacheConfig);

            if (objValue == null || objValue.GetType() != typeof(List <T>))
            {
                var pValue = pdelegate();
                if (pValue != null)
                {
                    if (pValue is IEnumerable <T> )
                    {
                        if ((pValue as IEnumerable <T>).Count() > 0)
                        {
                            //将缓存内容写入执行项中
                            pCacheConfig.CacheContent = pValue;
                            //每次从数据库中获取数据都添加到缓存中
                            pInterface.InsertCache(pCacheConfig, RemovedCallback);
                        }
                    }
                    else
                    {
                        //将缓存内容写入执行项中
                        pCacheConfig.CacheContent = pValue;
                        //每次从数据库中获取数据都添加到缓存中
                        pInterface.InsertCache(pCacheConfig, RemovedCallback);
                    }
                }
                return(pValue);
            }
            return(objValue as List <T>);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取缓存中的本地数据,如果缓存中缺少数据,则回调RecallDataFromLocal事件的数据
        /// </summary>
        /// <returns></returns>
        public static List <T> GetCacheList <T>(this IServiceXCache pInterface, RecallDataFromLocal <T> pdelegate, ICacheConfig pCacheConfig)
        {
            object objValue = GetCache(pInterface, pCacheConfig);

            if (objValue == null || objValue.GetType() != typeof(List <T>))
            {
                return(pdelegate());
            }
            return(objValue as List <T>);
        }
Esempio n. 3
0
 /// <summary>
 /// 清空缓存
 /// </summary>
 /// <param name="pInterface"></param>
 /// <param name="pCacheConfig"></param>
 public static void RemoveCache(this IServiceXCache pInterface, ICacheConfig pCacheConfig)
 {
     HttpRuntime.Cache.Remove(pCacheConfig.CacheTypeName);
 }
Esempio n. 4
0
 /// <summary>
 /// 获取缓存
 /// </summary>
 /// <param name="pInterface"></param>
 /// <param name="pCacheConfig"></param>
 /// <returns></returns>
 public static object GetCache(this IServiceXCache pInterface, ICacheConfig pCacheConfig)
 {
     return(HttpRuntime.Cache.Get(pCacheConfig.CacheTypeName));
 }
Esempio n. 5
0
 /// <summary>
 /// 插入缓存,覆盖旧有缓存
 /// </summary>
 /// <param name="pInterface"></param>
 /// <param name="pCacheConfig"></param>
 /// <param name="onRemove"></param>
 public static void InsertCache(this IServiceXCache pInterface, ICacheConfig pCacheConfig, CacheItemRemovedCallback onRemove)
 {
     HttpRuntime.Cache.Insert(pCacheConfig.CacheTypeName, pCacheConfig.CacheContent, pCacheConfig.Dependency, pCacheConfig.AbsoluteTime, pCacheConfig.SlidingTime, pCacheConfig.Priority, onRemove);
 }