memlim
memlim is a tiny in-memory cache library that can be used on limited size of memory.
Installation
$ npm install memlim
Usage
const memlim = 1000 * 1000 * 10; // 10MB cache at the most memlim; // put cache with no ttlmemlim; // with ttl (msec)memlim; // binary data memlim; // get data; memlim; // delete memlimfreeSize; // total free sizememlimusedSize; // total used size memlimdataCount; // total data count memlimclear; // clear all data
Overwrite Policies
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
"oldestAccess"
default
policy. Try to delete entries that was accessed on the oldest date.
"oldest"
Try to delete entries that was put on the oldest date.
"minSize"
Try to delete entries that has the minimum size in all data.
"maxSize"
Try to delete entries that has the maximum size in all data.
"clear"
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 = 12 adata;memlim;memlim;memlim;// will delete c("01")memlim;
entry's type schema is as below:
;
size
About 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.
LICENSE
MIT