cache policy in php
i retrieve data from database which consists of images as well as other fields and then encode it in json format using php script.Now the data is being requested from phone what i want to do is to use cache policy or something else i.e if there is something in mysql might be, to check whether the data is edited in database since last request or not so that when request comes to the page it will first check and then responed accordingly. which can save time, fast the request and also decrease the traffic on server.
i have read some notes about cache po开发者_开发知识库licy hereif some one help me along with example or code i shall be very thankful
MySQL can't tell you when a record was last modified, but it's very simple to do it yourself: simply add a timestamp
column to your tables in which you insert the current date and time each time you modify the record. MySQL can do this automatically by setting the initialization and update behaviors (see the MySQL reference):
CREATE TABLE t (
lastmodified TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP);
Then all you need to do is query that column along with your other data and check it against the If-Modified-Since
header sent by the client. If the date and time in your result are more recent than those given by the client, you return the data as you normally would. Otherwise, simply send the 304 Not Modified
header without the content to let the client know nothing has changed since the last request.
精彩评论