🐛 [Bug]: app.Static, CacheDuration of 0 does not work intuitively
Bug Description
Setting the CacheDuration to 0 in app.Static does not disable caching.
The minimum cache time is 1 * time.Nanosecond
How to Reproduce
Steps to reproduce the behavior:
- Create a project and use fiber to serve a static folder.
- Set the
CacheDurationas shown below. - Edit the
index.htmlin the static folder. - Notice how it does not change on refresh.
Expected Behavior
Disable caching for that static directory.
Fiber Version
v2.39.0
Code Snippet (optional)
package main
import "github.com/gofiber/fiber/v2"
import "log"
func main() {
app := fiber.New()
// The below will correctly serve `./public` but cache is not disabled
app.Static("/", "./public", fiber.Static{
Compress: true,
CacheDuration: 0,
})
/*
This code effectively disables the cache.
app.Static("/", dir, fiber.Static{
Compress: true,
CacheDuration: 1 * time.Nanosecond,
})
*/
app.Listen(":3000")
}
Checklist:
- [X] I agree to follow Fiber's Code of Conduct.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.
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, the challenge here is that we need to find out in the config which is passed if the value would be set or not
If it would not be set we take the default value for the cache duration
Since 0 is the value that is initially set for integer, your expected behavior collides with the previous explained one
Maybe we can disable the cache for negative values
Ahh I see. I was unsure if I should even label this a bug since it really just isn't intuitive, not necessarily a bug.
I think the negative values thing is a good idea.
I definitely would not have the default caching behavior be "no caching." Since I think in most cases I would be wanting to cache things.
The FS in fasthttp will set default CacheDuration val when param is less than or equal zero.
https://github.com/valyala/fasthttp/blob/v1.41.0/fs.go#L423.
wait for next version of valyala/fasthttp