How to cache server side response?
How to cache server side response?
gordyr
Posts: 35Questions: 0Answers: 0
I'm using datatables in many different ways on a particular site. One of those is to provide a Facebook style message preview function in what is essentially a large tooltip.
The user clicks the messages button at the top and a small 5 message preview is rendered, pulling the most recent messages from the database.
The preview button appends an element and table to the body, datatables is then initialised and the server is queried for the messages. When The user clicks anywhere else on the body or selects a message the whole thing is destroyed. (I wish to continue this behaviour and not simply hide it).
This all works beautifully and every request is <100ms.
However, every time the button is clicked the server is queried. I would like to be able to perform some sort of caching so that this only happens once per visit (or until a new message is recieved of course).
So essentially my question is...
How can I cache the server response? Is there any built in mechanism within datatables for achieving this?
If not Is there any way I can store the response in a variable within jQuery so that I can check against it having any contents upon the preview box opening. and if the variable does contain something, simply load that data rather than query the server.
Any ideas guys?
The user clicks the messages button at the top and a small 5 message preview is rendered, pulling the most recent messages from the database.
The preview button appends an element and table to the body, datatables is then initialised and the server is queried for the messages. When The user clicks anywhere else on the body or selects a message the whole thing is destroyed. (I wish to continue this behaviour and not simply hide it).
This all works beautifully and every request is <100ms.
However, every time the button is clicked the server is queried. I would like to be able to perform some sort of caching so that this only happens once per visit (or until a new message is recieved of course).
So essentially my question is...
How can I cache the server response? Is there any built in mechanism within datatables for achieving this?
If not Is there any way I can store the response in a variable within jQuery so that I can check against it having any contents upon the preview box opening. and if the variable does contain something, simply load that data rather than query the server.
Any ideas guys?
This discussion has been closed.
Replies
Allan
Many thanks as always Alan.