New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(httpcache): souin integration #2487
base: main
Are you sure you want to change the base?
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: cache I'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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice integration. Main issue: cache should only be enabled on prod env. Check api-platform/demo@73977b3 for example
# Good defaults for REST APIs | ||
defaults: | ||
stateless: true | ||
cache_headers: | ||
max_age: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP Cache Headers should only be set on prod env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)%'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
urls: ['%env(SOUIN_API_URL)%'] | |
urls: ['%env(SOUIN_API_URL)%'] | |
@@ -17,6 +17,8 @@ | |||
# API Platform distribution | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A declared env var without being used, especially in dev/test environments, will throw an error in Symfony commands
# Good defaults for REST APIs | ||
defaults: | ||
stateless: true | ||
cache_headers: | ||
max_age: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment still valid for max_age
header
@@ -6,6 +6,8 @@ | |||
|
|||
log | |||
|
|||
cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -36,6 +36,13 @@ services: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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