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

cache-money-flow

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-money-flow

LRU cache with locking

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Cache Flow Money

cache-flow-money is a simple LRU cache for node.

It supports both synchronous and asynchrous population for the cache, and it supports locking items so they cannot be evicted.

Installation

npm install cache-flow-money

Usage

var LRUCache = require('cache-flow-money');

var maxItems = 10;
var options = {
  populate: function(key) { return key + key; },
  async: false
};
var cache = new LRUCache(maxItems, options);

cache.get('foo') === 'foo-foo' // populated automagically

You can also use async populate methods.

var options = {
  populate: function(key, cb) {
    cb(key + "-" + key);
  },
  async: true
};

var cache = new LRUCache(maxItems, options);

cache.get('foo', function(v) {
  v === 'foo-foo'; // populated
});

Performance

Evicting items (which happens on inserts when cache is full), is O(n), with n being the number of items in the cache.

Everything else (retrieving, locking, unlocking, setting), is O(1).

Locking

You can lock items that are in use to prevent them from being evicted.

var cache = new LRUCache(5);

cache.set('foo', 'bar');
cache.set('baz', 'bam');
cache.lock('foo');
for (var i = 0; i < 10; ++i) {
  cache.set('foo' + i, i);
}

cache.get('foo'); // 'bar'
cache.get('baz'); // undefined

License

Cache-flow-money is under an MIT Style (jslint) license.

See the LICENSE file for details.

FAQs

Package last updated on 07 May 2012

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