2.1.0 • Published 7 years ago

cachd v2.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Cachd

A fast TTL Cache

for node >= 4.2

npm Travis node

About the memory mangement:

The cache stops caching more items if the memory is getting full (> 70% of the heap used). It accepts new items but removes the oldest ones before the ttl or max size is reached.

API

Create cache instance

var Cachd = require('cachd');


var myCache = new Cachd({
      ttl: 3600000                  // max age of items in msec (default: 3600000 -> 1h)
    , maxLength: 1000               // the maximum of items to store (default: 10000)
    , removalStrategy: 'leastUsed'  // remove the least used items if the cache is getting
                                    // too full (default: oldest)
});

Add item. You have to pass a unique hash and the value.

myCache.set(hash, value);

// alias of set
myCache.add(hash, value);

Check if an item exists

if (myCache.has(hash)) {
    // there it is ;)
}

Get an item

var item = myCache.get(hash);

Remove an item

myCache.remove(hash);

Get all hashes

var hashMap = myCache.getHashMap();

Get first cached item. This is the most accessed item if the cache has the «leastUsed» removal strategy, else its the most recent added item.

var item = mycache.getFirst();

Get last cached item. This is the least accessed item if the cache has the «leastUsed» removal strategy, else its the least recent added item.

var item = mycache.getFirst();

Events

the cache emits events when an item is added or one is removed

myCache.on('add', function(hash, value) {

});


myCache.on('remove', function(hash, value) {

});
2.1.0

7 years ago

2.0.0

7 years ago

1.0.0

9 years ago

0.3.7

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.1

9 years ago