Socket
Socket
Sign inDemoInstall

cachd

Package Overview
Dependencies
7
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cachd

A fast TTL Cache implementation


Version published
Maintainers
1
Install size
625 kB
Created

Readme

Source

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) {

});

Keywords

FAQs

Last updated on 11 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc