资 源 简 介
Enables short-term ajax response caching in user"s browser using JavaScript.
basic example:
lets say we have this code (below), ajax request is sent to server every time we want to obtain data. Which is not always necessary and results in more process time for server, more bandwidth usage and delay while waiting for the response.
$.ajax({ url: ajax_path, type: "GET", data: viewData, dataType: "json" success: function(response) { // update website update_website(response); }, error: function(xhr) { // handle errors handle_errors(xhr); },});
We can transform it to:
if(cache.on){ var cachedResponse = cache.get(ajax_path, [viewData]); if(cachedResponse !== false) { // update website update_website(cachedResponse); // We just avoided one ajax request return true; }}$.ajax({ url: ajax_path, type: "GET", data: viewData, dataType: "json" success: function(res