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.38k stars 353 forks source link

what does maxSize mean? #299

Closed stephenliu1944 closed 1 year ago

stephenliu1944 commented 1 year ago

it means total item size or each item size? what is the unit? what is the default value?

isaacs commented 1 year ago

it means total item size or each item size?

Total max size. The maximum size for a given entry can be specified as maxEntrySize.

what is the unit?

The unit is "number". You decide. To limit based on size, you can provide a sizeCalculation method in the constructor options, or either a sizeCalculation method or size value to the set() options. For cache.fetch() you can provide it in the options when calling fetch, or the fetchMethod can put it on the options object (for example, if you're fetching documents from a server, and don't know how big it is until you see the content-length header or something).

If the number is bigger than maxEntrySize, the item isn't cached. If the total of all the items in the cache is bigger than maxSize, then it'll drop old items until it's below the limit.

what is the default value?

There isn't one. If you specify a maxSize, then every item must be given a size, either via a sizeCalculation method, or via the size option at set() time.