0.2.1 • Published 5 months ago
node-share-memory-cache v0.2.1
Nodejs Shared Memory Cache
Usage
import { ShmCache } from 'node-share-memory-cache';
const cache = new ShmCache({
name: 'CacheNameV1',
size: 1024 * 1024 * 10,
maxSize: 1024 * 1024 * 100,
});
// set cache with ttl
cache.set('key','value', 1000 * 60 * 5);
// get cache
const value = cache.get('key');
// delete key
cache.del('key');
API
- get/set with key , base data operation
- setMaxAge , set max age for data expire,default 2000ms
- setMaxSize , set max memory allocation size, default 800MB
memory allocation
auto grow
shrink
when clean up, and free memory more than 40MB shrink to fit the size of data
read/write lock
- read with shared lock
- write with exclusive lock
- no timeout lock support (toto later add)
- memory grow/shrink with exclusive lock
benchmark
5 child process , read only, macbook pro
5 child process , read+write, macbook pro
5 child process , read first, macbook pro
5 child process , write first, win64 i5-12490