feat(httpcache): souin integration#2487
Conversation
Co-authored-by: Vincent <407859+vincentchalamon@users.noreply.github.com>
|
The following improvements could be great to add before merge:
|
|
Hey, do you have two different Caddyfiles (one for prod and another one for dev)? Assuming yes, just compile your docker image with the |
|
Is something like that would do the work? # docker-compose.prod.yml
services:
caddy:
environment:
CADDY_CACHE: cacheI'm wondering if the |
|
Why don't you link a
|
|
Using a But I don't find it as a good approach... I'm working on an implementation here: api-platform/demo@02e5026 EDIT: implementation commit amended: api-platform/demo@73977b3 |
|
Having a single Caddyfile will help with maintenance. It's possible to inject any global options in |
vincentchalamon
left a comment
There was a problem hiding this comment.
Nice integration. Main issue: cache should only be enabled on prod env. Check api-platform/demo@73977b3 for example
| defaults: | ||
| stateless: true | ||
| cache_headers: | ||
| max_age: 0 |
There was a problem hiding this comment.
HTTP Cache Headers should only be set on prod env
There was a problem hiding this comment.
Comment still valid for max_age header
2ec729b to
b80d9ff
Compare
b80d9ff to
6f0fb64
Compare
|
Ping @vincentchalamon |
| invalidation: | ||
| enabled: true | ||
| purger: 'api_platform.http_cache.purger.souin' | ||
| urls: ['%env(SOUIN_API_URL)%'] No newline at end of file |
There was a problem hiding this comment.
| urls: ['%env(SOUIN_API_URL)%'] | |
| urls: ['%env(SOUIN_API_URL)%'] | |
| 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)$ | ||
| # The api url that is called to invalidate cached resources | ||
| SOUIN_API_URL=http://caddy/souin-api/souin |
There was a problem hiding this comment.
A declared env var without being used, especially in dev/test environments, will throw an error in Symfony commands
| defaults: | ||
| stateless: true | ||
| cache_headers: | ||
| max_age: 0 |
There was a problem hiding this comment.
Comment still valid for max_age header
|
|
||
| log | ||
|
|
||
| cache |
There was a problem hiding this comment.
Should be enabled through an env var:
| cache | |
| {$CADDY_CACHE} |
Then, declare this env var in docker-compose.prod.yml and helm chart to only enable cache on production
| SERVER_NAME: ${SERVER_NAME:-localhost}, caddy:80 | ||
| MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} | ||
| MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} | ||
| CADDY_GLOBAL_OPTIONS: | |
There was a problem hiding this comment.
Do not enable cache on dev
|
I tried to implement it in the demo (cf. api-platform/demo#327) but had to rolled it back because it caused issues. If you want to try and improve this implementation in API Platform, you can test it (locally or with a fork of my branch) with this branch: https://github.com/api-platform/demo/tree/chore/refacto |
|
https://github.com/darkweak/souin/issues/new if you have issues using it. |
Obsoletes #2383