epicweb-dev / cachified

🤑 wrap virtually everything that can store by key to act as cache with ttl/max-age, stale-while-validate, parallel fetch protection and type-safety support
MIT License
926 stars 24 forks source link

Adapter bug with `swr` set to `Infinity` #86

Closed assensamuelsson closed 10 months ago

assensamuelsson commented 10 months ago

We have written our own adapter for ioredis and took inspiration from the official redis adapters provided in this repo.

Our use case is that we want to set swr to Infinity so that all keys should be stored in Redis forever and basically be updated in the background by cachified. The official repos does not seem to take swr into account when determining if the key in Redis should expire or not and we're wondering if there is a bug here or if there is something we're missing?

I'm providing a failing test case in a Pull Request to demonstrate my point. https://github.com/epicweb-dev/cachified/pull/85

kentcdodds commented 10 months ago

The problem is Infinity doesn't serialize as a number. I would recommend just setting it to a very high number (like Number.MAX_SAFE_INTEGER) which is hundreds of thousands of years ago it should be enough.

I think I prefer that solution over coming up with our own serialization solution.

Hope that helps! If you'd like to make a contribution to the docs about this, I welcome it 😁