How to remove Output Cache by param

Platform: ASP.NET| Category: Output Caching

You can attach a cache dependency to the response that is unique per query param, then invalidate the dependency for the particular param:

VB.NET


’add cache item dependency on response 
Dim cacheKey As String = 'webform1.aspx?' + queryParam
Cache(cacheKey) = New Object() ’
Response.AddCacheItemDependency(cacheKey)

’ invalidate the dependency 
Dim cacheKey As String = 'webform1.aspx?' + queryParam
Cache.Remove(cacheKey)

C#


// add cache item dependency on response 
string cacheKey = 'webform1.aspx?' + queryParam; 
Cache[cacheKey] = new object(); 
Response.AddCacheItemDependency(cacheKey); 

// invalidate the dependency 
string cacheKey = 'webform1.aspx?' + queryParam; 
Cache.Remove(cacheKey); 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.