Skip to content

Latest commit

 

History

History
67 lines (39 loc) · 2.93 KB

README.md

File metadata and controls

67 lines (39 loc) · 2.93 KB

Two Buckets Memcache

Memcache that trades a simplified expiry strategy for a super low resource consumption

Build Status Coverage Status Dependency Status

Installation

NPM Stats

This is a module for node.js and is installed via npm:

npm install two-buckets-memcache --save

What is special about this memory cache?

Schematic

The milliseconds you pass to the constructor define how soon the cache moves to a new bucket. The newest bucket is always the one in which new entries are stored. After the given milliseconds this bucket gets retired and is only used to get old cache entries. The second time the given milliseconds elapse, the retired bucket gets deleted and the old cache entries it contains expire with it. As a result a stored cache entry expires after 1x to 2x the given milliseconds, i.e. 10-20 seconds.

This design allows a super low resource consumption:

  • Just a single timer is used, instead of one timer for each cache entry like many other memcaches do.
  • The asymptotic runtime for .get(...) and .set(...) is still O(1) like you would expect.

Usage

var TwoBucketsMemcache = require('two-buckets-memcache');

var cache = new TwoBucketsMemcache(10000); // Entries expire in 10-20 seconds.

cache.set('some key', { any: value });

cache.get('some key'); // -> { any: value }

cache.get('unknown key'); // -> throws an Error

cache.destroy(); // if cache is not needed anymore

Contributing

To set up your development environment for Quota:

  1. Clone this repo to your desktop,
  2. in the shell cd to the main folder,
  3. hit npm install,
  4. hit npm install gulp -g if you haven't installed gulp globally yet, and
  5. run gulp dev. (Or run node ./node_modules/.bin/gulp dev if you don't want to install gulp globally.)

gulp dev watches all source files and if you save some changes it will lint the code and execute all tests. The test coverage report can be viewed from ./coverage/lcov-report/index.html.

If you want to debug a test you should use gulp test-without-coverage to run all tests without obscuring the code by the test coverage instrumentation.

Change History

  • v0.1.0 (2015-10-16)
    • Initial version

License (ISC)

In case you never heard about the ISC license it is functionally equivalent to the MIT license.

See the LICENSE file for details.