日期:2014-05-17  浏览次数:20413 次

asp.net


   public static List<Group_User> GetGroupByUid(int Uid)
        {
            Group_UserBLL bll = new Group_UserBLL();
            string key = "groupuser_by_uid" + Uid;//KEY值是如何设置?如何方法GetGroupByUid(int A,int B)传入的参数是2个,key值是怎么的?
            List<Group_User> data = (List<Group_User>)HttpRuntime.Cache[key];
            // 检查缓存
            if (data == null)
            {
                //如果数据不存在缓存中,则重新读取数据库
                data = bll.GetGroupUid(Uid);
                try
                {
                    AggregateCacheDependency cd = TableDependency();//这句话建立缓存依赖项有什么作用
                    //将数据写入缓存
                    HttpRuntime.Cache.Insert(key, data, cd, DateTime.Now.AddHours(Timeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return data;
        }

求解释下这几行代码,绝对迷茫中。谢谢,最好详细点 谢谢
------解决方案--------------------
一,key 是一个标识:
说明当前的缓存数据里面是以什么样的形式取出来的,相当于一个类别
二,如果当前的这个又传入的标识和缓存里面的标识不一样,那就证明需要取数据,然后继续放到缓存中

这个逻辑好像不是很难吧?