-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
Can't get cache-handler to work #1062
Comments
Tried to call
FrankenPHP posts to log:
calling 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 |
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.
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.
< HTTP/1.1 200 OK
< Content-Type: application/json
< Permissions-Policy: browsing-topics=()
< Server: Caddy
< Date: Fri, 04 Oct 2024 12:44:06 GMT
< Content-Length: 279
<
["GET-https-api.*.-/icons/1{-VARY-}Accept:text%2Fhtml%2Capplication%2Fxhtml%2Bxml%2Capplication%2Fxml%3Bq%3D0.9%2Cimage%2Favif%2Cimage%2Fwebp%2Cimage%2Fapng%2C%2A%2F%2A%3Bq%3D0.8%2Capplication%2Fsigned-exchange%3Bv%3Db3%3Bq%3D0.7;Content-Type:;Authorization:;Origin:"]
api-1 | 2024/10/04 12:44:04.798 ERROR the current responseWriter is not a flusher {"error": "feature not supported"}
Relevant log output
The text was updated successfully, but these errors were encountered: