Why TTL value is string instead of number
NafieAlhilaly opened this issue ยท comments
Hey, cool project ๐๐ค
I was exploring your project and came across
Line 15 in b22e632
and wondered ๐ค why did you choose to give ttlString
the type of string instead of a number.
using numbers can reduce confusion and make you avoid the string parsing headache.
Best of luck.
Hey! Thanks for pointing it out, a lot of memory cache libraries in Nodejs go with the approach of saving the TTL
as a number in ms
.
However, I found this to be problematic in some cases (still not a big deal), as such, when you want to save a value for a long time the TTL
value will be a large number.
Yes, the ttlString
approach has a parsing headache, but easier to deal with for us, humans.
I don't think saving a big number would be an issue, as long as you are staying consistent across the codebase and with other caching tools, preferring consistency over easier to deal with
.
Remember you do not have to stick with ms
, you can accept seconds
(Redis use seconds) and then change it to ms
behind the scene.
Sure, will be considered ๐