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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With