How to cache server side response?

How to cache server side response?

gordyrgordyr Posts: 35Questions: 0Answers: 0
edited November 2011 in DataTables 1.8
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?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    There is the pipelining example which does response caching that you might find useful / interesting: http://datatables.net/release-datatables/examples/server_side/pipeline.html .

    Allan
  • gordyrgordyr Posts: 35Questions: 0Answers: 0
    Great! I'm sure I can modify this to suit my purpose.

    Many thanks as always Alan.
This discussion has been closed.