根据条件查找数组中的一条数据并放入缓存

protected MemberInfo GetCacheMemberInfo(string userName)
    {
        MemberInfo minfo = new MemberInfo();//实体
        minfo = System.Web.HttpRuntime.Cache.Get("HotPP_" + userName) as MemberInfo;//读缓存
        if (minfo == null)
        {
            MemberInfo[] minfos = SASAPIHelper.GetMembers(1);
            List<MemberInfo> mlist = new List<MemberInfo>();
            mlist.AddRange(minfos);
            //委托
            Predicate<MemberInfo> mpush = new Predicate<MemberInfo>(delegate(MemberInfo info) { return info.Name == userName; });
            minfo = mlist.Find(mpush);

            //加缓存
            System.Web.HttpRuntime.Cache.Insert("HotPP_" + userName, minfo, null, DateTime.Now.AddMinutes(30), System.Web.Caching.Cache.NoSlidingExpiration);
        }
        return minfo;//返回实体
    }

你可能感兴趣的:(根据条件查找数组中的一条数据并放入缓存)