diff --git a/api/.env b/api/.env index 23a3542f1..5d9d82318 100644 --- a/api/.env +++ b/api/.env @@ -19,6 +19,8 @@ TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 TRUSTED_HOSTS=^(localhost|caddy)$ OIDC_SERVER_URL=https://localhost/oidc/realms/demo OIDC_SWAGGER_CLIENT_ID=api-platform-swagger +# The api url that is called to invalidate cached resources +SOUIN_API_URL=http://caddy/souin-api/souin ###> symfony/framework-bundle ### APP_ENV=dev diff --git a/api/Dockerfile b/api/Dockerfile index d036635e9..e5da64650 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -119,7 +119,7 @@ ARG TARGETARCH WORKDIR /srv/app # Download Caddy compiled with the Mercure and Vulcain modules -ADD --chmod=500 https://caddyserver.com/api/download?os=linux&arch=$TARGETARCH&p=github.com/dunglas/mercure/caddy&p=github.com/dunglas/vulcain/caddy /usr/bin/caddy +ADD --chmod=500 https://caddyserver.com/api/download?os=linux&arch=$TARGETARCH&p=github.com/dunglas/mercure/caddy&p=github.com/dunglas/vulcain/caddy&p=github.com/caddyserver/cache-handler /usr/bin/caddy COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile diff --git a/api/config/packages/api_platform.yaml b/api/config/packages/api_platform.yaml index 5fe081e2d..18c75c45b 100644 --- a/api/config/packages/api_platform.yaml +++ b/api/config/packages/api_platform.yaml @@ -9,9 +9,17 @@ api_platform: graphql: graphql_playground: false mercure: ~ + http_cache: + public: true + invalidation: + enabled: false + purger: 'api_platform.http_cache.purger.souin' + urls: ['%env(SOUIN_API_URL)%'] defaults: stateless: true cache_headers: + max_age: 0 + shared_max_age: 3600 vary: ['Content-Type', 'Authorization', 'Origin'] extra_properties: standard_put: true @@ -28,6 +36,12 @@ api_platform: scopes: openid: (required) Indicates that the application intends to use OIDC to verify the user's identity +when@prod: + api_platform: + http_cache: + invalidation: + enabled: true + services: app.filter.review.admin.search: class: 'ApiPlatform\Doctrine\Orm\Filter\SearchFilter' diff --git a/api/docker/caddy/Caddyfile b/api/docker/caddy/Caddyfile index 969c0dc11..6b5961f3e 100644 --- a/api/docker/caddy/Caddyfile +++ b/api/docker/caddy/Caddyfile @@ -1,12 +1,20 @@ { # Debug {$CADDY_DEBUG} + order cache before rewrite + cache { + api { + souin + } + } } {$SERVER_NAME} log +cache + # Matches requests for OIDC routes @oidc expression path('/oidc/*')