Symfony2 反向代理返回“陈旧无效" [英] Symfony2 reverse proxy returns "stale invalid"

查看:25
本文介绍了Symfony2 反向代理返回“陈旧无效"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Symfony2 反向代理缓存通过以下设置启用(在开发环境中测试):

Symfony2 reverse proxy cache is enabled with the following settings(testing in the dev environment):

class AppCache extends HttpCache
{
    protected function getOptions()
    {
        return array(
            'debug'                  => true,
            'default_ttl'            => 20,
            'private_headers'        => array(),
            'allow_reload'           => false,
            'allow_revalidate'       => false,
            'stale_while_revalidate' => 21,
            'stale_if_error'         => 60,
        );
    }
}

来自服务器的响应如下.

The responses from the server are following.

来自第一个请求(如预期):

From the first request(as expected):

X-Symfony-Cache:GET /api/posts?pageNumber=1: miss, store

来自第二个请求和 20 秒内的所有后续请求(正如预期的那样,内容从缓存中提供):

From the second request and all subsequent requests within 20 seconds(as expected, content being served from cache):

X-Symfony-Cache:GET /api/posts?pageNumber=1: fresh

来自 20 秒后的请求(有问题):

From the requests after 20 seconds(problematic):

X-Symfony-Cache:GET /api/posts?pageNumber=1: stale, invalid

对于陈旧、无效响应,我不是从反向代理缓存中获得响应,而是从经历 MVC 周期的服务器获得响应.

With the stale, invalid response, I get response not from the reverse proxy cache, but from the server that going through MVC cycle.

感觉这里有几件事失败了:

Feels like a couple things failed here:

  • 未从缓存中提供过时的内容;
  • 缓存未被重新验证;

有什么想法可以寻找原因吗?

Any ideas where to look for a cause?

推荐答案

这在我看来很正常.

您提到从缓存中提供过时的内容是有问题的.然而,这是正常行为.陈旧"意味着内容超过了它的 ttl(生存时间),不应再从缓存中提供.因此再次命中服务器,以获取新内容并重新填充缓存.

You mention that it is problematic that stale content is being served from the cache. However, this is normal behaviour. 'Stale' means that the content surpassed its ttl (time to live) and should not be served from the cache anymore. Therefore the server is hit again, to get fresh content and repopulate the cache.

这篇关于Symfony2 反向代理返回“陈旧无效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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