【问题标题】:HTTP cache invalidation with API Platform and AWS CloudFrontAPI 平台和 AWS CloudFront 的 HTTP 缓存失效
【发布时间】:2022-01-23 18:54:50
【问题描述】:

我正在尝试使用 API 平台和 AWS CloudFront 实现 HTTP 缓存失效,正如我在 API Platform documentation 中看到的那样:

通过实现ApiPlatform\Core\HttpCache\PurgerInterface,可以轻松添加对 Varnish 以外的反向代理的支持

我已经编写了一个实现,但现在我无法制作内置缓存失效系统 - 应该是事件侦听器 ApiPlatform\Core\Bridge\Doctrine\EventListener\PurgeHttpCacheListener- 它只是继续注入 ApiPlatform\Core\HttpCache\VarnishPurger

我基本上做了什么,config/services.yml - 启用了自动接线:

    ApiPlatform\Core\HttpCache\PurgerInterface: '@App\ApiPlatform\HttpCache\CloudFrontPurger'

    ApiPlatform\Core\Bridge\Doctrine\EventListener\PurgeHttpCacheListener:
        arguments:
            $purger: '@App\ApiPlatform\HttpCache\CloudFrontPurger'

有什么想法吗?

【问题讨论】:

    标签: amazon-cloudfront api-platform.com http-caching


    【解决方案1】:

    好的!发现问题。 PurgeHttpCacheListener 正在使用服务 ID,因此无法自动连接 according to the Symfony docs

    来自vendor/api-platform/core/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_http_cache_purger.xml

            <service id="api_platform.doctrine.listener.http_cache.purge" class="ApiPlatform\Core\Bridge\Doctrine\EventListener\PurgeHttpCacheListener">
                <argument type="service" id="api_platform.http_cache.purger" />
                <argument type="service" id="api_platform.iri_converter" />
                <argument type="service" id="api_platform.resource_class_resolver" />
    
                <tag name="doctrine.event_listener" event="preUpdate" />
                <tag name="doctrine.event_listener" event="onFlush" />
                <tag name="doctrine.event_listener" event="postFlush" />
            </service>
    

    解决方案很简单。在您的 service.yml 中,只需使用其服务 ID 注入它,如下所示:

        api_platform.http_cache.purger:
            class: App\ApiPlatform\HttpCache\CloudFrontPurger
    

    【讨论】:

      猜你喜欢
      • 2019-02-22
      • 1970-01-01
      • 2021-12-16
      • 2017-10-01
      • 2019-04-25
      • 2015-04-29
      • 2012-10-23
      • 2018-04-16
      • 2018-11-17
      相关资源
      最近更新 更多