I'm using MVC3 - i have a javascript function that uses jQuery get() to get a PartialView from a controller.
The problem is that it's being cached and i keep getting stale content back.
I've tried [OutputCache(Duration=0)] on the action, thinking it would prevent it caching, but no joy. Could it be the client caching it too?
EDIT:
I've recently been using another way to prevent caching which may be useful to some.
$.get("/someurl?_="+$.now(),function(data) {
// process data
});
It's obviously not as clean, but because each request passes a _=12345678
(timestamp) it's never cached.
Hope it helps.
You can clear the markup from the partial view using empty() : $('#EditTestSection'). empty();
cache:true is the default and does not always get the content from the cache. The cache-ability of an item on the browser is determined by: The response headers returned from the origin web server. If the headers indicate that content should not be cached then it won't be.
GET requests could be automatically cached by the browser so you could use the .ajax()
function which contrary to the .get()
function allows you to disabled caching:
$.ajax({
url: '/foo',
type: 'GET',
cache: 'false',
success: function(result) {
}
});
Another possibility is to use POST:
$.post('/foo', function(result) {
});
IE is particularly bad about that. You can disable all AJAX caching with the following:
$.ajaxSetup({
cache: false
});
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