Beispiel #1
0
        /// <summary>
        /// 根据指定的键值获取缓存项
        /// </summary>
        public virtual TEntity GetItem(TKey key)
        {
            if (key == null)
            {
                return(null);
            }

            DynamicListCacheInner <TEntity, TKey> cacheObj = GetCacheObj();

            TEntity result;

            cacheObj.ItemsDic.TryGetValue(key, out result);
            return(result);
        }
Beispiel #2
0
        private DynamicListCacheInner <TEntity, TKey> GetCacheObj()
        {
            DynamicListCacheInner <TEntity, TKey> cacheObj = DynamicCache.Instance.GetData <DynamicListCacheInner <TEntity, TKey> >(_CacheKey);

            if (cacheObj == null)
            {
                List <TEntity> items = LoadCacheItems();
                if (items == null)
                {
                    items = new List <TEntity>();
                }

                cacheObj          = new DynamicListCacheInner <TEntity, TKey>();
                cacheObj.Items    = items;
                cacheObj.ItemsDic = GetItemsDic(items);

                //加入动态缓存
                DynamicCache.Instance.Add(_CacheKey, cacheObj, DateTime.Now.Add(GetCacheDuration()));
            }

            return(cacheObj);
        }
Beispiel #3
0
        /// <summary>
        /// 获取所有的缓存项集合
        /// </summary>
        public virtual List <TEntity> GetAll()
        {
            DynamicListCacheInner <TEntity, TKey> cacheObj = GetCacheObj();

            return(cacheObj.Items.ToList());
        }