flowpack/fullpagecache

缓存完整的Neos页面响应

安装次数: 55,092

依赖项: 1

建议者: 1

安全: 0

星级: 14

关注者: 14

分支: 9

开放问题: 2

类型:neos-package

3.0.1 2022-12-06 20:10 UTC

README

此包旨在缓存完整的HTTP响应,以实现超快的交付时间。目前它支持Neos,但也在计划提供Flow的功能。

它的工作原理是检查页面是否可以完全缓存,如果是,则缓存整个HTTP响应并立即交付。因此,这对每个页面都包含未缓存元素的网站影响不大。此外,POST请求和带有查询参数的请求以及设置cookie的请求都不参与缓存。因此,如果您安装后没有看到差异,请注意这些因素。

设置

有两个设置可供您影响行为。

Flowpack:
  FullPageCache:
    # enable full page caching
    enabled: true

    # the maximum public cache control header sent
    # set to 0 if you do not want to send public CacheControl headers
    maxPublicCacheTime: 86400

    # requests have to fulfill certain conditions for beeing cached
    request:
      # !!! Only the http methods "GET" and "HEAD" are supported !!!

      # a request will only qualify for caching if it contains no cookieParams that
      # are not ignored.
      cookieParams:
        # ignored cookie params exclude cookies that are handled by the frontend
        # and are not relevant for the backend. A usecase would be gdpr consent cookies
        # if they are only used on the client side
        ignore: []

      # a request will only qualify for caching if it only contains queryParams that
      # are allowed or ignored. All other arguments will prevent caching.
      queryParams:
        # allowed params become part of the cache identifier, use this for
        # arguments that modify the reponse but still allow caching like pagination
        allow: []

        # ignored arguments are not part of the cache identifier but do not
        # prevent caching either. Use this for arguments that are meaningless for
        # the backend like utm_campaign
        ignore: []

您还可以将缓存后端移动到更快的某种东西,以进一步提高性能。

工作原理

该包定义了两个HTTP中间件

  • RequestCacheMiddleware:如果请求可缓存,则首先询问缓存,只有当找不到响应时,请求才被传递到中间件链。缓存生命周期和标签由上游中间件或控制器设置的 X-FullPageCache-EnabledX-FullPageCache-LifetimeX-FullPageCache-Tags 确定。此外,中间件还添加了 ETagCache-Control 标头,考虑了生命周期并设置了 maxPublicCacheTime

  • FusionAutoconfigurationMiddleware:连接到Fusion缓存,提取标签和允许的生存时间,然后存储在响应头 X-FullPageCache-EnabledX-FullPageCache-LifetimeX-FullPageCache-Tags 中。此组件仅在响应中存在 X-FullPageCache-EnableFusionAutoconfiguration 标头时才处于活动状态,该标头自动用于 Neos.Neos:Page

希望直接控制缓存行为的自定义控制器可以设置 X-FullPageCache-EnabledX-FullPageCache-LifetimeX-FullPageCache-Tags 标头,而基于Fusion的控制器可以通过设置 X-FullPageCache-EnableFusionAutoconfiguration 标头来启用自动配置。

警告

此包仍然相对较新,如果您安装它,请确保仔细检查页面是否仍然工作。特别是像表单和插件这样的东西。理想情况下,这些页面应该工作,但不像纯内容页面那样快。尽管如此,到目前为止,这只在有限场景中进行了测试,因此在使用此包进入生产之前,请确保正确测试。它对内容本身没有影响,因此卸载它将使您回到之前的状态。