Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

akv-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

akv-cache

Asynchronous key-value cache

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

akv-cache

Asynchronous in-memory key-value cache.

Installation

npm install akv-cache

Usage

var cache = require('akv-cache')({
    /*
     * Global time-to-live
     * Default: 0
     */
    ttl: 10,

    /*
     * Cache grace period
     * Default: 0
     */
    grace: 60,

    /*
     * Default value when cache is empty
     * Default: undefined
     */
    emptyValue: undefined,

    /*
     * Function for retrieval of fresh data
     * Default: function(key, callback) { callback(null); }
     */
    miss: function(key, callback) {
        setTimeout(function() {
            /* callback(err, value, [ttl]) */
            callback(null, 'Data is here!');
        }, 1000);
    }
});
get(key, [scope], [callback]): mixed
/*
 * Using a callback will guarantee a value, as it will wait for it to be generated.
 */

cache.get('some-key', function(err, value) {
    if (err) return console.error(err);

    console.log('Got value: ' + value);
});


/*
 * Using the return value will result in `undefined` if the cache
 * is empty or during data generation without a grace period.
 */

var value = cache.get('some-key');


/*
 * Provide additional data to the miss-function by overriding the default function scope.
 */

cache.get('key', { data: 123 }, function(err, value) { });
set(key, value, [ttl]): akv-cache
cache.set('key1', 'some value');

cache
    .set('key2', 'other value')
    .set('key3', 'third value', 15);
has(key): boolean
var keyExists = cache.has('some-key');
size(): integer
var cacheSize = cache.size();

License

MIT

Keywords

FAQs

Package last updated on 24 Aug 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc