问题
I am using javascript gmail api to fetch email threads using threadId. I am using the following code:
var request = gapi.client.gmail.users.threads.get({
'userId': 'me',
'id': '123abc'
});
request.execute(function(response) {
var messages = response.messages;
});
For the first time for a particular threadId it's working fine. And for further requests its returning the same number of messages even if the thread has more emails. But the response gives correct number of emails if I am clearing the browser cache of the gapi url from the Chrome developer tools - network option.
Example:
-> Executed the request with a threadId '123abc', presently the thread has 3 emails in it. The response for the request is correct with length 3 for response.messages
.
-> Then I sent one more email as reply to this thread, then executed the same request again. But the response is still the old one with length 3 for response.messages
.
-> Tried running the same request many times but getting the same response.
-> Then cleared the browser cache for this url and requested again, now the response is correct with length 4 for response.messages
.
Tried adding following meta tag in the html page, but didn't work:
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
Tried adding a random number with the page url and the request, but didn't work.
Tried adding random number with gapi script link, but didn't work <script src="https://apis.google.com/js/client.js?onload=AuthIt&cacheBurster=123123123123"></script>
Is there any code to disable gapi request caching or any other method to solve this issue?
回答1:
Finally got the solution by adding a random number to 'metadataHeaders' field in the gapi request:
var request = gapi.client.gmail.users.threads.get({
'userId': 'me',
'id': '123abc',
'metadataHeaders': Math.random()
});
来源:https://stackoverflow.com/questions/38869484/disable-gmail-api-request-caching