Ejemplo 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>);
        }
Ejemplo 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>);
        }