【问题标题】:GAE java cache problemsGAE java缓存问题
【发布时间】:2014-10-24 17:16:20
【问题描述】:

我正在 Google App Engine 中开发 Java 应用程序,但遇到了问题。 我希望能够从管理控制台控制应用程序数据库,但它似乎无法正常工作,当我更改数据库中的数据时,它不会反映在应用程序上,即我有一个我想锁定的用户所以我更改了值 active = "false",我可以在数据库中看到新值,但是当应用程序发出另一个请求时,我得到了以前的值作为回报(以 JSON 格式)。

我假设它带有缓存,所以我尝试从 JavaScript 和 Java 中取消它,如下所示:

JavaScript:

$.ajaxSetup({
    cache: false,
    type: 'POST',
    headers: {
        "cache-control": "'no-cache, max-age=0",
        "Pragma": "no-cache"
    }
});

Java:

response.addHeader("Cache-Control", "no-cache, private, must-revalidate, max-age=0");
response.addHeader("Pragma", "no-cache");

我还能做什么?

【问题讨论】:

    标签: java javascript google-app-engine http caching


    【解决方案1】:

    我发现了我的问题,不是缓存问题,而是持久性管理器的问题。

    我使用了 2 个 PM 实例,这就是出现差异的原因。

    【讨论】:

      【解决方案2】:

      您可以尝试配置您的服务器。假设 apache:

      # mod_expires directives: 
      # enable expires/max-age headers and set default to 0 seconds from last access time
      ExpiresActive On
      ExpiresDefault A0
      # configure ExpiresByType on your specific types, eg ExpiresByType text/css A0
      
      # mod_headers directives:
      # send variety of no-cache directives, should cover any quirky clients and gateways
      Header set Cache-Control "max-age=0, private, no-cache, no-store, must-revalidate, proxy-revalidate, no-transform"
      Header set Pragma "no-cache"
      # enclose this in <Files> directive for specific file eg <Files *.js>
      

      这是一篇解释网页缓存的好文章:http://www.mnot.net/cache_docs/

      【讨论】:

      猜你喜欢
      • 2013-09-30
      • 1970-01-01
      • 2021-11-18
      • 2011-08-12
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多