コード例 #1
0
        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <param name="cacheName">缓存名称</param>
        /// <param name="entity">缓存值</param>
        /// <returns></returns>
        public static void RemoveEntityCache(object id)
        {
            string thisCacheName = cacheName + "_" + id.ToString();

            CachesHelper.Remove(thisCacheName);

            AddCacheNames(thisCacheName, false);
        }
コード例 #2
0
        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <param name="cacheName">缓存名称</param>
        /// <param name="entity">缓存值</param>
        /// <returns></returns>
        public static void AddEntityCache(object id, T entity)
        {
            string thisCacheName = cacheName + "_" + id.ToString();

            CachesHelper.Set(thisCacheName, entity);

            AddCacheNames(thisCacheName);
        }
コード例 #3
0
        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns></returns>
        public static List <T> GetAllEntityCache()
        {
            List <string> names = CachesHelper.Get(cacheListName) as List <string>;

            if (names == null)
            {
                return(null);
            }
            List <T> list = new List <T>();

            foreach (string name in names)
            {
                var value  = CachesHelper.Get(name);
                T   entity = (T)value;
                list.Add(entity);
            }
            return(list);
        }
コード例 #4
0
        /// <summary>
        /// 添加缓存名称至缓存名称列表
        /// </summary>
        /// <param name="thisCacheName"></param>
        /// <param name="isAdd">是否为添加缓存值,true为添加,false为移除</param>
        private static void AddCacheNames(string thisCacheName, bool isAdd = true)
        {
            List <string> list = CachesHelper.Get(cacheListName) as List <string>;

            if (list == null)
            {
                list = new List <string>();
            }
            if (list.Contains(thisCacheName))
            {
                if (isAdd == false)
                {
                    list.Remove(thisCacheName);
                }
            }
            else
            {
                if (isAdd)
                {
                    list.Add(thisCacheName);
                }
            }
            CachesHelper.Set(cacheListName, list);
        }
コード例 #5
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static T GetEntityCache(object id)
        {
            string thisCacheName = cacheName + "_" + id.ToString();

            return((T)CachesHelper.Get(thisCacheName));
        }