在SqlDataSource的清除缓存 [英] Clear cache in SqlDataSource

查看:118
本文介绍了在SqlDataSource的清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要手动清除缓存与一个SqlDataSource启用缓存。我试过设置EnableChaching = false和CacheDuration = 0(以及= 1),并没有似乎已经到期的内容在缓存中 - 虽然他们被缓存似乎prevent新的SELECT

I need to manually clear the cache on a SqlDataSource with caching enabled. I've tried setting EnableChaching = false, and CacheDuration = 0 (as well as = 1) and none seem to expire the content already in the cache - although they do seem to prevent new SELECTs from being cached.

如何手动过期的缓存?

感谢。

推荐答案

我刚开始今天这个研究和碰到这个职位,这一下喜欢最好的解决办法:

I just started researching this today and came across this post, this look likes the best solution:

简单的方法无效的SqlDataSource缓存编程

<asp:SqlDataSource ID="x" EnableCaching="True" CacheKeyDependency="MyCacheDependency"/>

protected void Page_Load(object sender, EventArgs e)
{ // Or somewhere else before the DataBind() takes place
  if (!IsPostBack)
  {
      //prime initial cache key value if never initialized
      if (Cache["MyCacheDependency"] == null)
      {
        Cache["MyCacheDependency"] = DateTime.Now;
      }
  }
}


// Evict cache items with an update in dependent cache:
Cache["MyCacheDependency"] = DateTime.Now;

这篇关于在SqlDataSource的清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆