memlim is a tiny in-memory cache library that can be used on limited size of memory.
$ npm install memlim
const memlim = 1000 * 1000 * 10; // 10MB cache at the mostmemlim; // put cache with no ttlmemlim; // with ttl (msec)memlim; // binary datamemlim; // get data;memlim; // deletememlimfreeSize; // total free sizememlimusedSize; // total used sizememlimdataCount; // total data countmemlimclear; // clear all data
Memlim will try to reuse space for new data when total used size exceeded the limitation.
By default, memlim deletes data which was accessed (by
put/get) at the oldest date.
This policy can be changed by passing the policy value to constructor.
const overwrite = "___"; // set overwrite policyconst memlim = 100 overwrite
default policy. Try to delete entries that was accessed on the oldest date.
Try to delete entries that was put on the oldest date.
Try to delete entries that has the minimum size in all data.
Try to delete entries that has the maximum size in all data.
custom compare function
You can pass arbitrary compare function between entries.
When compare function was given, memlim will sort entries by that and delete the first entry recursively until total free size exceeds size to be added.
const memlim = 12adata;memlim;memlim;memlim;// will delete c("01")memlim;
entry's type schema is as below:
memlim only limits cache's
content size. This means that
key and associated JS object's sizes are not measured and not included in memlim's size. Be careful to determine size to use for caching.