Currently the cache middleware uses a hard coded c.Path() as cache key.
Sometimes a more complicated cache key is required, so please add a configuration option to support a custom cache key function.
https://github.com/gofiber/fiber/blob/master/middleware/cache/cache.go#L126
Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
Hi @marcusti, could you elaborate an use case on why c.Path() is not the best identifier? Just curious ^^
Hey @Fenny, I have an API where the path references a resource. Example: /news gives a list of articles.
Then I use query parameters on GET requests as resource filters. Example: /news?limit=5 gives 5 articles. Etc...
Since c.Path() does not include query parameters, I get wrong cache hits. c.OriginalURL() would be a solution.
I agree this is a flaw in our implementation. I'll make a pr later today.
I think a similar approach like https://github.com/gofiber/fiber/blob/master/middleware/limiter/limiter.go#L36 would be valid, I currently don't have time to make the PR myself but will accept one using the above implementation 馃憤
Most helpful comment
Hey @Fenny, I have an API where the path references a resource. Example: /news gives a list of articles.
Then I use query parameters on GET requests as resource filters. Example: /news?limit=5 gives 5 articles. Etc...
Since
c.Path()does not include query parameters, I get wrong cache hits.c.OriginalURL()would be a solution.