{"id":235,"date":"2010-08-20T18:24:29","date_gmt":"2010-08-20T22:24:29","guid":{"rendered":"http:\/\/www.peteonsoftware.com\/?p=235"},"modified":"2024-03-01T17:32:11","modified_gmt":"2024-03-01T22:32:11","slug":"the-importance-of-jquery-ajaxsetup-cache","status":"publish","type":"post","link":"https:\/\/www.peteonsoftware.com\/index.php\/2010\/08\/20\/the-importance-of-jquery-ajaxsetup-cache\/","title":{"rendered":"The Importance of jQuery ajaxSetup Cache"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.peteonsoftware.com\/images\/Aug2010\/JohnnyCache.jpg\" alt=\"Johnny Cache\" title=\"Johnny Cache\" style=\"float:left; margin:.5em;\" \/><br \/>\nJust a quick note to document a &#8220;gotcha&#8221; that cost me quite a bit of time today.  I am currently working on my company&#8217;s second Asp.Net MVC 2.0 application.  Our first one was a huge success and (to me) MVC is way more fun and productive than WebForms, so doing as much new development using MVC instead of WebForms is a no-brainer.<\/p>\n<p>Being good MVC-ites, we are doing a lot of AJAX calls.  Since we are extensively using the jQuery library, we do a lot of $.ajax() and $(someSelector).load() in our code to make calls.  Today, I was calling code like the following:<br \/>\n<br style=\"clear:both;\" \/><\/p>\n<pre>\r\n$('#theDivToUpdate').load('\/Our\/Url\/Product\/Edit\/', {id : ourIdParameter}, function() { \/* callback logic *\/ });\r\n<\/pre>\n<p>That code will call the Edit action on the ProductController and pass in the id of the product to edit.  The controller gets the product details and then returns a partial to the page, which is then inserted into the div.  I was trying to debug the controller action, but after I had edited a product once, the breakpoint wouldn&#8217;t catch anymore.  I figured that I was dealing with a caching issue and the method wasn&#8217;t even being called, but I couldn&#8217;t find where I even had output caching configured in MVC.  <\/p>\n<p>I knew that I wasn&#8217;t having this problem in our previous application, so I started comparing files and looking for answers.  Nothing was really giving me any clues, and everything appeared to be set up the same way.  Finally, in exasperation, I did a &#8220;Find in Files&#8221; in Visual Studio in the other solution for just the word &#8220;cache&#8221; since searching for &#8220;outputcache&#8221; had failed me.  <\/p>\n<p>I dug through tons of results and then finally came across this little gem:<\/p>\n<pre>\r\n$.ajaxSetup({ cache: false });\r\n<\/pre>\n<p>I had seen that in the last application, had read the documentation on <a href=\"http:\/\/api.jquery.com\/jQuery.ajaxSetup\/\">ajaxSetup<\/a>, but I didn&#8217;t really understand all of the ramifications of it.<\/p>\n<p>Apparently, jQuery in all of its awesomeness will actually cache ajax calls for you to speed up your page.  That&#8217;s definitely awesome, but unexpected caching can certainly screw up your day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just a quick note to document a &#8220;gotcha&#8221; that cost me quite a bit of time today. I am currently working on my company&#8217;s second Asp.Net MVC 2.0 application. Our first one was a huge &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,50],"tags":[89,112],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-code-tips","category-jquery","tag-code-tips","tag-jquery"],"_links":{"self":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":0,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}