using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BookDemo.QA
{
public class UserInfoCache : BaseCache<List<QAUserInfo>>
{
    public const string CACHE_KEY = "QAUserInfo";
    public UserInfoCache()
        : base(CACHE_KEY)
    {
        base._timeout = 30;
    }

    /// <summary>
    /// 更新缓存方法
    /// </summary>
    /// <returns></returns>
    public override List<QAUserInfo> Update()
    {
        //设置缓存依赖参数
        System.Web.Caching.SqlCacheDependency sqlCacheDependency =
            new System.Web.Caching.SqlCacheDependency(
                "BookDemo",//对应Web.config中sqlCacheDependency\databases参数中的name
                "QAUserInfo"//对应数据库表的名称
                );

        BookDemoEntities ctx = new BookDemoEntities();//创建Linq to Entities的对象上下文实例
        List<QAUserInfo> userInfos = (from u in ctx.QAUserInfo select u).ToList();
        //写入缓存
        base.SetData(userInfos, base._timeout, sqlCacheDependency, null);
        return userInfos;//返回最新的缓存中的信息
    }
}
}
