Ideally, I need to cache Ajax requests and if there have been changes to check and update the cache.
Here is an example on JS and PHP, how can I understand queries cached or not?
// js
$.ajax ({
Type: 'Post',
URL: '/ AJAX / SEARCH_Objects /',
Data: {
Search_category: Categories, // Show the first 12 results
Query: _this.val () // Search phrase
},
Cache: True,
SUCCESS: FUNCTION (DATA, STATUS, XHR) {
},
Error: Function () {
}
})
// PHP.
Header ("Content-Type: Application / JSON; Charset = UTF-8");
Header ("Cache-Control: Public, Max-Age = 3600, Must-Revalidate");
Header ('Pragma: Cache');
Print JSON_ENCODE ($ suggestions);
/// In response comes the title
Cache-Control: Public, Max-Age = 3600, Must-Revalidate
Connection: Close.
Content-Encoding: Gzip
Content-Type: Application / JSon; Charset = UTF-8
Date: Thu, 19 Nov 2015 18:41:15 GMT
Pragma: Cache.
Answer 1, Authority 100%
iFModified (Default: False)
Type: Boolean.
ALLOW THE REQUEST TO BE SUCCESSFUL ONLY If The Response Has Changed Since The Last Request. This Is Done by Checking The Last-Modified Header. Default Value Is False, Ignoring The Header. In JQuery 1.4 This Technique Also Checks The ‘Etag’ Specified by The Server to Catch Unmodified Data.cache (Default: True, False for Datatype ‘script’ and ‘jsonp’)
Type: Boolean.
If Set to False, It Will Force Requested Pages Not to Be Cached by The Browser. Note: Setting Cache to False Will Only Work Correctly with Head and Get Requests. It Works by Appending “_ = {timestamp}” To the Get Parameters. The Parameter Is Not Needed for Other Types of Requests, Except in Ie8 WHEN A POST IS MADE TO A URL THAT HAS ALREADY BEEN REQUESTED BY A GET.
You can still use a proxy (nginx or apache mod_proxy) and then cached answers to catch a 301-code