isaacs / node-lru-cache

A fast cache that automatically deletes the least recently used items
http://isaacs.github.io/node-lru-cache/
ISC License
5.35k stars 353 forks source link

Unclear maxSize documentation #342

Closed drgrice1 closed 4 months ago

drgrice1 commented 4 months ago

Your documentation states that setting maxSize will limit the overall storage size, but it does not clarify what the unit of the number for that size is. Is it bits, bytes, kilobytes, megabytes, etc? Presumably it is bytes, but that is not stated, leaving it quite unclear what numerical setting is needed to obtain the desirable limit.

drgrice1 commented 4 months ago

How exactly does the maxSize depend on the sizeCalculation setting? That is not clearly stated in the documentation. That may be the answer instead of a fixed unit.

isaacs commented 4 months ago

The definition of "size" is up to you. As far as this library is concerned, it's just a number that the sizeCalculation returns for some key/value pair. That could be bits, bytes, or bananas.

You can also specify the size in the set() options, if you want to state it at that point, instead of in a method that calculates it.

But "what it means" is up to you. You decide.

kudlav commented 2 days ago

Hi, how is the total size calculated? When is the sizeCalculation called? Is it called only at the insertion or called periodically for all items?

Only on insert / remove, no periodic check.

The size of items may change.

Put the item into the cache with the same key and new size.