Fiber: 馃殌 add configuration option for key in cache mw

Created on 29 Oct 2020  路  5Comments  路  Source: gofiber/fiber

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

馃槑 Nice to Have 馃洜 In Progress

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.

All 5 comments

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 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GrigoriyMikhalkin picture GrigoriyMikhalkin  路  4Comments

mewben picture mewben  路  3Comments

Ivan-Feofanov picture Ivan-Feofanov  路  3Comments

bashery picture bashery  路  4Comments

ahan picture ahan  路  3Comments