禁用gmail api请求缓存 [英] Disable gmail api request caching

查看:73
本文介绍了禁用gmail api请求缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript gmail api使用threadId获取电子邮件线程。
我使用以下代码:

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;

});

这是第一次特定的threadId,它运行正常。并且对于进一步的请求,即使线程有更多的电子邮件,它也会返回相同数量的消息。
但是,如果我从Chrome开发者工具 - 网络选项中清除gapi网址的浏览器缓存,则响应会提供正确数量的电子邮件。

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.

示例:

- >使用threadId'123abc'执行请求,目前线程中有3封电子邮件。对于 response.messages ,请求的响应是正确的,长度为3。

-> 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.

- >然后我又发送了一个电子邮件作为回复此线程,然后再次执行相同的请求。但是响应仍然是旧的,长度为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.

- >尝试运行相同的请求多次但得到相同的响应。

-> Tried running the same request many times but getting the same response.

- >然后清除此网址的浏览器缓存并再次请求,现在响应正确,长度为4 response.messages

-> Then cleared the browser cache for this url and requested again, now the response is correct with length 4 for response.messages.

尝试在html页面中添加以下元标记,但无效:

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.

尝试使用gapi脚本链接添加随机数,但无法正常工作< script src =https://apis.google.com/js /client.js?onload=AuthIt&cacheBurster=123123123123\"></script>

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请求缓存或任何其他方法来解决这个问题?

Is there any code to disable gapi request caching or any other method to solve this issue?

推荐答案

最后通过在'metadataHeaders'字段中添加一个随机数来获得解决方案gapi请求:

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()
});

这篇关于禁用gmail api请求缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆