1

I have the following jquery code:

Client side javascript Code:

         $.ajax({
                url: "/MyController/GetOrders",
                cache: false, dataType: "json"
            }).done(function (data) {

                FilloutTable(data.Orders);
            });

asp.net-mvc Controller Code:

    [CompressFilter]
    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult GetOrders()
    {
        var orders = Model.GetOrders();
        return Json(new{Orders= orders}, JsonRequestBehavior.AllowGet);
    }

I have a few cases with a few users where they are not seeing the latest data. When i have them clear out their browser cache and do a hard refresh, it then works fine.

I thought the

 cache: false,

would protect me against any browser caching on this request. Any suggestion for what could be still being cached here and any suggestion for a solution to make sure people don't get old data?

leora
  • 188,729
  • 360
  • 878
  • 1,366

1 Answers1

0

You can set output cache attribute on Action:

    [OutputCache(VaryByParam = "*", Duration = 0, NoStore = true)]
    public ActionResult AcyionName()
    {

The above code will disable caching for particular Action.

Note that u can prevent caching on controller level also as follows:

[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
public class ControllerName : Controller
{
     // ... 
 }
Jatin patil
  • 4,252
  • 1
  • 18
  • 27
  • but where do you see any serverside caching going on? – leora Sep 16 '13 at 18:59
  • Your behaviour could be due to fact that browser is caching the page and serving it from browser cache, one way to verify this is to check the traffic via Fiddler , you can watch the traffic and see if the Url is generated via 304 http status code response instead of 200. 304 suggest it is coming from cache. – Jatin patil Sep 17 '13 at 06:04
  • For more on caching have a look here: http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/improving-performance-with-output-caching-cs – Jatin patil Sep 17 '13 at 06:05
  • why would I have to do that . . Isn't it not cached by default? – leora Sep 26 '13 at 16:16