Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how the caching in your scenario works. Suppose you define the following action</p> <pre><code>[OutputCache(VaryByParam = "none", Duration = 5)] public ActionResult AjaxCache() { return Json(new { date = DateTime.Now }, JsonRequestBehavior.AllowGet); } </code></pre> <p>If you don't explicitly set the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.outputcacheattribute.location.aspx" rel="nofollow noreferrer">Location</a> attribute it default to <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.outputcachelocation.aspx" rel="nofollow noreferrer">OutputCacheLocation.Any</a> which means:</p> <blockquote> <p>The output cache can be located on the browser client (where the request originated), on a proxy server (or any other server) participating in the request, or on the server where the request was processed. This value corresponds to the HttpCacheability.Public enumeration value.</p> </blockquote> <p><code>Duration = 5</code> means that the contents will be cached for 5 seconds. Next you send ajax request:</p> <pre><code>&lt;%= Html.ActionLink("cache test", "AjaxCache") %&gt; &lt;script type="text/javascript"&gt; $(function() { $('a').click(function() { $.ajax({ url: this.href, success: function(json) { $('#result').html(json.date); } }); return false; }); }); &lt;/script&gt; &lt;div id="result"&gt;&lt;/div&gt; </code></pre> <p>If you click on the link twice during 5 seconds interval you will see that the result div will not change neither the server action will be hit but the <code>success</code> callback will always execute. The server sends the following headers:</p> <pre><code>Cache-Control: public, max-age=5 Expires: Fri, 26 Feb 2010 14:09:02 GMT Last-Modified: Fri, 26 Feb 2010 14:08:57 GMT Vary: * </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload