简体   繁体   English

禁用gmail api请求缓存

[英]Disable gmail api request caching

I am using javascript gmail api to fetch email threads using threadId. 我正在使用javascript gmail api来使用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. 这是第一次特定的threadId,它工作正常。 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. 但是,如果我从Chrome开发者工具 - 网络选项中清除gapi网址的浏览器缓存,则响应会提供正确数量的电子邮件。

Example: 例:

-> Executed the request with a threadId '123abc', presently the thread has 3 emails in it. - >使用threadId'123abc'执行请求,目前线程中有3封电子邮件。 The response for the request is correct with length 3 for response.messages . 对请求的响应是与长度为3正确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 . 但反应仍然是旧的与长度为3 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 . - >然后清除此URL的浏览器缓存并再次请求,现在响应正确, response.messages长度为4。

Tried adding following meta tag in the html page, but didn't work: 尝试在html页面中添加以下元标记,但不起作用:

<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> 尝试使用gapi脚本链接添加随机数,但无法正常工作<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? 是否有任何代码可以禁用gapi请求缓存或任何其他方法来解决此问题?

Finally got the solution by adding a random number to 'metadataHeaders' field in the gapi request: 最后通过在gapi请求中的'metadataHeaders'字段中添加一个随机数来得到解决方案:

var request = gapi.client.gmail.users.threads.get({
  'userId': 'me',
  'id': '123abc',
  'metadataHeaders': Math.random()
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM