Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bypass OutputCache in ASP.NET MVC

I am using the OutputCache attribute in my MVC website as follows:

[OutputCache(Duration = 5000,
        VaryByParam = "name;region;model;id;op;content;featured;isStarred;page;size;")]

However sometimes I'd like to bypass the output cache entirely and force a fetch from the database. This is especially true for my test environment where I am continuously loading new data in to the database for testing.

Is there anyway I could bypass the cache in this case?

Thanks.

like image 656
Cranialsurge Avatar asked Jan 11 '11 20:01

Cranialsurge


1 Answers

This doesn't exactly answer your question but answers your title (which is not "how to clear an item from the cache"): You could add a "VaryByParam":

[OutputCache(Duration=5000,VaryByParam="YourExistingParams;CacheBypass")]

then when you want to bypass the cache you simply pass the CacheBypass parameter the value of DateTime.UtcNow.Ticks (or any random thing) => for example: http://localhost/?CacheBypass=1234567890

like image 152
Vincent Avatar answered Oct 28 '22 03:10

Vincent