I am trying to cache the result of a JQuery. This is my Ajax call:
$.ajax({
dataType: "json",
url: myEndPoint,
type:"GET",
cache:true,
startTime: performance.now(),
data: {"query": myQuery,
"output": "json"},
success: createDisplay,
error: myError
});
console.log('After .ajax');
};
I am trying to do this so that I minimize the amount of Ajax calls as I noticed that it takes about 2.4s to get the results which results in a lag time on the web user interface. In the networks console window I can see that the query is being re-executed even if it has been performed before. What am I doing wrong? Can I see the cached contents anywhere?
Sure you can store it on localStorage. There is also a library that does just that: cache4.js
It is a wrapper for the jQuery ajax call. Just pass to it what you would pass to $.ajax.
[EDIT] Sure Simas Joneliunas Although I can guarantee that the docs will stay the same, as I own the repository. Using the question example, it would be something like this:
cache4js.ajaxCache({
dataType: "json",
url: myEndPoint,
context: {
startTime: performance.now()
}
data: {
"query": myQuery,
"output": "json"
},
success: createDisplay,
error: myError
}).then(function (res){
console.log('After .ajax');
});