Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear cache in SqlDataSource

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.

How do I manually expire that cache?

Thanks.

like image 782
azollman Avatar asked Jun 01 '09 20:06

azollman


1 Answers

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

Simple way to invalidate SqlDataSource cache programmatically

<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;
like image 98
Chris Marisic Avatar answered Sep 29 '22 01:09

Chris Marisic