From c8dba7eb945ced900b929719f8ca99af596c1df8 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:10:06 +0200 Subject: [PATCH] feat: add Souin --- api/.env | 2 ++ api/Dockerfile | 2 +- api/config/packages/api_platform.yaml | 8 ++++++++ api/docker/caddy/Caddyfile | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) 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..204b13cb7 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: true + 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 diff --git a/api/docker/caddy/Caddyfile b/api/docker/caddy/Caddyfile index 969c0dc11..7e2dcd0ce 100644 --- a/api/docker/caddy/Caddyfile +++ b/api/docker/caddy/Caddyfile @@ -1,12 +1,16 @@ { # Debug {$CADDY_DEBUG} + order cache before rewrite + cache } {$SERVER_NAME} log +cache + # Matches requests for OIDC routes @oidc expression path('/oidc/*')