pamelafox / lscache

A localStorage-based memcache-inspired client-side caching library.
Other
1.46k stars 160 forks source link

Expiry time less or a fraction of a minute #71

Closed elliotlings closed 6 years ago

elliotlings commented 7 years ago

Does the expiry time have to be a whole minute and it can it be less than a minute?

karlhiramoto commented 7 years ago

Change the EXPIRY_UNITS. https://github.com/pamelafox/lscache/blob/master/lscache.js#L44

elliotlings commented 7 years ago

That is not possible if you import the module.

peter-gribanov commented 6 years ago

I also don't understand why it was necessary to count the expiration time in minutes.

pamelafox commented 6 years ago

I'm afraid I don't remember why I decided to do it as minutes. I probably had never had a use case where I needed to have an expiry of less than 1 minute. We can't change the expiry unit now, as that'd break the API, but someone could send a PR that has a method to reset the expiry units, or a PR that rewrites the internal code so that fractional times work. (*If possible)

mikehedman commented 6 years ago

+1 Actually, my primary interest is unit testing. If I have 5 tests, I'd REALLY like to be able to set expiration times in milliseconds.

mikehedman commented 6 years ago

I had written a bunch of the code to implement this, was looking to testing, and discovered this line in your existing tests: lscache.set(expiredKey, 'blech', 1/60); // Expire after one second ~This 100% settled my needs. I had wondered why the "time" argument was classified as a {number} and not an {int}, this is why!~
~I did a bit of experimentation, and it looks to me like using "fractional minutes" works just fine.~~ The tests work because with a 1/60 expiration it actually expires instantaneously. It looks to me like fractional times do NOT work currently.