title: How does ASP.NET MVC caching work for an AJAX request?
body: <p>I'm just starting to look in to caching to improve performance and have a question about caching for an AJAX call.</p>
  
  <p>I have a action which is used to query twitter and then return the results. At the moment when a user presses a button it loads a rotating gif whilst it goes off to the action to do the query and then return a partial view. jQuery then updates a div with the HTML response from the view.  Normally this takes around 5 secs. They then have a more button which goes off to get more results.</p>
  
  <p>What will happen if I put the CachingAttribute over this action? I know I can try it but I just want the technical side of things explained.</p>
  
  <p>Thanks</p>
  
  <p>Here is my Javascript:</p>
  
  <pre><code>$('#blogEntryList #moreLink').live("click", function() {
  
  
                  $('#morespan').toggle();
                  $('#loader').toggle();
  
                  $.get($(this).attr("href"), function(response) {
                      $('#blogEntryList ol').append($("ol", response).html());
                      $('#blogEntryList #moreLink').replaceWith($("#moreLink", response));
                      $('#loader').hide();
                      $('#morespan').show();
                  });
                  return false;
              });
  </code></pre>
  
  <p>Here is my modified Action:</p>
  
  <pre><code>[OutputCache(
      Location = OutputCacheLocation.Server,
      Duration = 100,
      VaryByParam = "")]
          public ActionResult BlogPosts(int? entryCount)
          {
              if (!entryCount.HasValue)
                  entryCount = defaultEntryCount;
  
              int page = entryCount.Value / defaultEntryCount;
  
              IEnumerable&lt;BlogData&gt; pagedEntries = GetLatestEntries(page, defaultEntryCount);
  
              if (entryCount &lt; totalItems)
                  AddMoreUrlToViewData(entryCount.Value);
  
              return View("BlogEntries", pagedEntries);
          }
  </code></pre>