Open mmjurov opened 3 weeks ago
Tried to call /flush
method, which clears all keys from storage, and seems it correctly works.
curl -v -X PURGE http://localhost/souin-api/souin/flush
* Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> PURGE /souin-api/souin/flush HTTP/1.1
> Host: localhost
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 204 No Content
< Permissions-Policy: browsing-topics=()
< Server: Caddy
< Date: Fri, 04 Oct 2024 14:13:56 GMT
<
* Connection #0 to host localhost left intact
FrankenPHP posts to log:
api-1 | Successfully clear the cache and the surrogate keys storage.
calling GET http://localhost/souin-api/souin
after that shows, that keys are really cleared.
Invalidation in that case works as expected. Calling GET operation on /icons/1 receive 200 Ok with cache miss, because there are no cache in storage.
Tried to call curl -v -X PURGE -H "Surrogate-Key: /icons" http://localhost/souin-api/souin
, like ApiPlatform does - no effect and no log entries on that.
Just FYI it looks like you're dumping an app secret. Not sure if important, just in case you missed it.
@nickdnk Thank you for your notice! It's okay, it's a dev environment on my local workstation behind NAT, not available from internet directly.
I went deeper and it seems that lots of previous info are not related to FrankenPHP, but related to ApiPlatform. My fault was in misunderstanding cache key generation and flushing mechanism. ApiPlatform do not flush cache of item when new item was created in a collection (i was expected it is). Also my saving mechanism for my ApiResource was broken, so cache flushing on PATCH request was not working, and cache was not flushed because of this. So pardon, it's not an issue anymore. My bad
The only one bug, possibly related to FrankenPHP - is an error message on cache miss with any cache storage, mentioned here, and error messages for otter storage. But probably it's not interfere application at all in my case. A can't figure out if this have any effect or not. I see, that cache is storing and flushing correctly now.
What happened?
I want to do some HTTP caching to make API faster. My final point is to use 103 Early Hints + HTTP cache on reverse proxy side with invalidation via Souin API.
According to the docs, i need to rebiuld FrankenPHP Docker image to include cache-handler module there, and one of available storage drivers. Then I need to do some configuration in Caddy and api_platform and then it should work.
What i've made:
One difference from the docs is additional Otter storage module.
cache
with some config andcache
option in my application config. My full featured, minimal config here:The only one thing here, not highlighted in docs - is otter storage configured. I believe, that it's zero-config in-memory storage, which just should work.
API Platform config updated. Added configuration for cache purger:
Added cache headers for one of my ApiResource's operation:
After that, http caching started to work. Cache headers are present in responses from reverse proxy and seems to be ok. On the first hit by operation it shows cache miss, and declares cache lifetime, status 200 Ok
On the second hit it shows cache ttl, cache storage, etc. Statud 304 Not Modified.
Quite ok .... but ... there are some symptoms showing it not work properly:
I can't see s-maxage in response (I don't really know, maybe i shouldn't). My Vary headers in config differs from Vary headers in response.
In Caddy (FrankenPHP) logs i can see some strange stuff:
On the first hit by operation after Caddy startup i see error, that key cannot be found in Otter:
On every 304 response logs not producing any output.
On every cache miss (200 Ok) i can see the following error from FrankenPHP:
I'm expecting, that when i calling
GET http://localhost/souin-api/souin
orGET http://localhost/souin-api/souin/surrogate_keys
, it will respond me the list of stored cache keys. Calling this request with curl from inside a container returns empty list with 200 Ok:PURGE http://localhost/souin-api/souin
, but it has no effect, as i see. Cache isn't invalidated, and reverse proxy continues to respond with 304 Not Modified after invalidation request from purger.I tried to call curl requests to PURGE by myself:
Same result with all my surrogate keys for that operation.
Also i tried to change cache storage to badger instead of otter:
root@4c566d2e930b:/app# curl -v -X GET http://localhost/souin-api/souin Note: Unnecessary use of -X or --request, GET is already inferred.
BTW. If i call PURGE after that and GET /souin-api/souin again, the key is still exists. Maybe i use PURGE request not very properly.
And again, i see FrenkenPHP errors on every cache miss response
So, I see one error, which i can't understood, and possibly it's a signal to non working cache-handler inside FrankenPHP environment. I try to figure out, where the problem is - inside FrankenPHP, or inside Souin. And the main question, what should i do to fix that behavior.
And probably another one problem with Otter, which is relevant, but not bother me.
Thank you!
Build Type
Docker (Debian Bookworm)
Worker Mode
No
Operating System
macOS
CPU Architecture
Apple Silicon
PHP configuration
Relevant log output