-
Hello there! I want to start off by saying that this looks insane and a job well done. I don't mean to be rude in any way whatsoever when I'm asking this question, but I just wondered, what would be a use-case for this library? I don't have a lot of knowledge about caching so that's likely the main reason why I don't understand the benefits of this library. I just wondered, aren't JS variables also stored in memory? What would be the difference with storing values in variables on the fly using I simply just want to learn! 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Well, the sweet spot would be "when you need caching but running Redis/Memcached would be an overkill". For example, in puter.com we utilize it for rate limiting etc., and by using KV.js we don't really have to bundle Redis with the codebase (or Dockerize it). |
Beta Was this translation helpful? Give feedback.
-
I'd like to add to this, having a Redis-like api right off the bat makes it much easier to move to Redis later if your requirements for scaling and distribution change. You can use the TTL/expiration mechanisms just like you would in Redis and then it's not a huge refactor to make the switch. |
Beta Was this translation helpful? Give feedback.
You're right, I missed the part about kv.js vs variables.
For simple
set
,get
,del
,... using variables is the obvious choice. Things get a little redundant when we needexpire
,expireat
and other secondary operations where, for example, we need a loop to check for expiry and "garbage collection". Before kv.js I had to re-write these for every use case e.g. rate-limiting, token caching, etc. so I just abstracted these parts away into a class calledkvjs
.There is also one more thing to note,
expire
,ttl
... seem simple on the surface but in order to do them efficiently we need to do a lot of non-trivial optimizations (e.g. the check interval should be as long as the shortestttl
). This is n…