关于SqlCacheDependency缓存机制的使用疑问

weixin_38106414 2017-11-28 11:30:54
这几天在调试依赖缓存的使用,试了两种方式:
1,轮询方式
             using (BASEEntities db = new BASEEntities())
            {
                //如果没有缓存 重新获取数据
                var links = db.Promotions.AsQueryable();
                //添加到缓存中
                HttpRuntime.Cache.Insert(
                    "Link",
                    links,
                    new SqlCacheDependency("DEV_BASE", "Promotions")
                    );
                //返回数据
                list = links.ToList();
            }

2,通知方式
            DataTable dtPromotions = HttpRuntime.Cache["dtPromotions"] as DataTable;

            if (dtPromotions == null)
            {
                Response.Write("no cache <br />");
                using (SqlConnection sqlCon = new SqlConnection(CONNSTR))
                {
                    sqlCon.Open();
                    SqlCommand sqlCmd = new SqlCommand();
                    sqlCmd.Connection = sqlCon;
                    sqlCmd.CommandText = "select employeeno, employeename from dbo.Promotions";
                    dtPromotions = new DataTable();
                    SqlCacheDependency scd = new SqlCacheDependency(sqlCmd);
                    SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
                    sda.Fill(dtPromotions);
                    HttpRuntime.Cache.Insert("dtPromotions", dtPromotions, scd);
                    sqlCon.Close();
                }

            }
            else
            {
                Response.Write("read cache <br />");
            }
两种方式都调试成功了。但想在通知方式中,使用EF 实体架构来实现,碰到了瓶颈。难道EF只能使用轮询方式吗?求解

...全文
8 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复

434

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧