I'm just starting to look for caching to improve performance and ask a question about caching for AJAX calls.
I have an action that is used to request a twitter and then returns the results. At that moment, when the user clicks the button, he loads the rotating gif, while he goes to the action to execute the request, and then returns a partial view. JQuery then updates the div with the HTML response from the view. It usually takes about 5 seconds. Then they have another button that goes away to get more results.
What happens if I put a CachingAttribute on this action? I know that I can try, but I just want to explain the technical side of things.
thanks
Here is my Javascript:
$('#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; });
Here is my modified action:
[OutputCache( Location = OutputCacheLocation.Server, Duration = 100, VaryByParam = "")] public ActionResult BlogPosts(int? entryCount) { if (!entryCount.HasValue) entryCount = defaultEntryCount; int page = entryCount.Value / defaultEntryCount; IEnumerable<BlogData> pagedEntries = GetLatestEntries(page, defaultEntryCount); if (entryCount < totalItems) AddMoreUrlToViewData(entryCount.Value); return View("BlogEntries", pagedEntries); }
caching asp.net-mvc asp.net-mvc-2
Jon
source share