Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }