0ss / mmry

Simple, Typed and Powerful memory cache in Typescript โœจ

Home Page:https://www.npmjs.com/package/mmry

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why TTL value is string instead of number

NafieAlhilaly opened this issue ยท comments

Hey, cool project ๐Ÿ‘‹๐Ÿค“

I was exploring your project and came across

public put(key: string, value: T, ttlString?: string): void {

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.

commented

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.

commented

Sure, will be considered ๐Ÿ‘