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

Caching happens only on the 2nd request to the endpoint #26

Closed
webwizrd opened this issue Nov 1, 2021 · 3 comments
Closed

Caching happens only on the 2nd request to the endpoint #26

webwizrd opened this issue Nov 1, 2021 · 3 comments

Comments

@webwizrd
Copy link

webwizrd commented Nov 1, 2021

When requesting an endpoint, which in turn accesses an external API, the first request to the endpoint does not get cached, only the second one. The same happens after the cache entry expires. The first request after expiry does not get cached, only the second.


GET /character/95334664 [STARTED]
res statuscode:200
GET /character/95334664 [FINISHED] 172.248 ms
GET /character/95334664 [CLOSED] 173.735 ms

GET /character/95334664 [STARTED]
res statuscode:200
GET /character/95334664 [FINISHED] 137.996 ms
GET /character/95334664 [CLOSED] 138.306 ms

[apicache] adding cache entry for "get/character/95334664{}" @ 1 minute - 139ms
@arthurfranca
Copy link
Owner

I'll try to reproduce the behavior you are experiencing but i have the following questions:

What apicache-plus version are you using? Check with npm list apicache-plus
Are you using it with express or another framework?
Are you using redis or regular memory store? If redis, is it node-redis or io-redis and what version?
Can you show a simplified version of your route middleware config?

@arthurfranca
Copy link
Owner

@webwizrd Caching happens on first response, but the debug statement is delayed a bit, because caching finishes some time after response has already been sent (caching doesn't block response, it starts together but ends a bit later).

You can see it is all working as intended when you slow down the request rate.

@webwizrd
Copy link
Author

I can see it working when slowing the request rate - thanks!

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

No branches or pull requests

2 participants