title: ASP.NET output caching - dynamically update dependencies
body: <p>I have an ASP.NET application which requires output caching. I need to invalidate the cached items when the data returned from a web service changes, so a simple duration is not good enough.</p>
  
  <p>I have been doing a bit of reading about cache dependencies and think I have the right idea. It looks like I will need to create a cache dependency to my web service.</p>
  
  <p>To associate the page output with this dependency I think I should use the following method:</p>
  
  <p>Response.AddCacheItemDependency(cacheKey);</p>
  
  <p>The thing I am struggling with is what I should add to the cache?</p>
  
  <p>The dependency my page has is to a single value returned by the web service. My current thinking is that I should create a  Custom Cache Dependency via subclassing CacheDependency, and store the current value in the cache. I can then use Response.AddCacheItemDependency to form the dependency.</p>
  
  <p>I can then periodically check the value and for a NotifyDependencyChange in order to invalidate my cached HTTP response.</p>
  
  <p>The problem is, I need to ensure that the cache is flushed immediately, so a periodic check is not good enough. How can I ensure that my dependant object in the cache which represents the value returned by the web service is re-evaluated before the HTTP response is fetched from the cache?</p>
  
  <p>Regards, Colin E.</p>