Memcache that trades a simplified expiry strategy for a super low resource consumption
This is a module for node.js and is installed via npm:
npm install two-buckets-memcache --save
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.
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
To set up your development environment for Quota:
- Clone this repo to your desktop,
- in the shell
cd
to the main folder, - hit
npm install
, - hit
npm install gulp -g
if you haven't installed gulp globally yet, and - run
gulp dev
. (Or runnode ./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.
- v0.1.0 (2015-10-16)
- Initial version
In case you never heard about the ISC license it is functionally equivalent to the MIT license.
See the LICENSE file for details.