Skip to content
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: add support for souin #2383

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JacquesDurand
Copy link

@JacquesDurand JacquesDurand commented Feb 10, 2023

Q A
Branch? main
Tickets #1947
License MIT
Doc PR api-platform/docs#1720

Hi !
This is a first attempt to integrate Souin, a HTTP Cache handler that can be built as a module for Caddy. This is still a work in progress.
It contains a seemingly minimal caddy configuration, as well as some configuration for api-platform to handle cache and invalidation.

Note: composer.lock is here as api-platform/core contains necessary bug fixes concerning the SurrogateKeyPurger class that are not yet integrated in the distribution (coming in api-platform/core:3.1.2 if I am not mistaken. The updated composer.lock won't be needed anymore soon.

What works:

  • xcaddy build in Dockerfile
  • caching through Surrogate-keys:
    image

What I am not sure about:

  • Invalidation:
    With the current configuration, the SouinPurger is called on postFlush when an ApiResource is modified (PATCH request for instance), and the PURGE request is made to the souin API (https://localhost/souin-api/souin by default) with the correct headers.

Here is an exemple of what caddy receives (and responds):

image

Nevertheless, requesting GET /greetings after said PATCH request still hits the cache

What still needs to be figured out:

  • Souin security, and access to its API only with JWT

@JacquesDurand
Copy link
Author

Note: after a discussion with souin maintainer (cf here), Surrogate Keys invalidation on postFlush has been resolved

@JacquesDurand JacquesDurand marked this pull request as ready for review February 14, 2023 14:13
@darkweak
Copy link

darkweak commented Feb 14, 2023

By the way, FYI the JWT authentication by Souin itself will be deprecated on the next minor release I'm working on.

Comment on lines 27 to 29
cache * {

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The braces and * matcher are not necessary.

Suggested change
cache * {
}
cache

api/Dockerfile Outdated
@@ -98,7 +98,8 @@ FROM caddy:2-builder-alpine AS app_caddy_builder

RUN xcaddy build \
--with github.com/dunglas/mercure/caddy \
--with github.com/dunglas/vulcain/caddy
--with github.com/dunglas/vulcain/caddy \
--with github.com/darkweak/souin/plugins/caddy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces -> tabs

Suggested change
--with github.com/darkweak/souin/plugins/caddy
--with github.com/darkweak/souin/plugins/caddy

@darkweak
Copy link

Ping @soyuka

@soyuka
Copy link
Member

soyuka commented Mar 23, 2023

what about http-tests/cache-tests#112 ?

If it works I'm 👍 on merging this, @dunglas ?

@darkweak
Copy link

That’s almost done, I have some points to discuss about the expectations.

@darkweak
Copy link

I think we can merge that while talking about the default behavior when no Cache-Control header given. They expect to not cache the response but the RFC doesn't give informations on that. (cc @mnot)

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Is it possible to simplify the Caddy config and just use the defaults provided by Souin?

@darkweak
Copy link

The Caddyfile could just set the cache directive because by default it stores for 2 minutes. @JacquesDurand

Comment on lines +6 to +18
allowed_http_verbs GET POST
api {
souin
}
cdn {
dynamic
provider default
}
ttl 1000s
timeout {
backend 10s
cache 100ms
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allowed_http_verbs GET POST
api {
souin
}
cdn {
dynamic
provider default
}
ttl 1000s
timeout {
backend 10s
cache 100ms
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants