mapclone / locking

Read I/O locking using LRU cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

locking

Build Status

Wraps any loader function of the form loader(id, callback) to use an LRU cache and lock I/O operations across concurrent calls.

var Locking = require('@mapbox/locking');
var fs = require('fs');
var readFile = Locking(fs.readFile);

// Reads file once, calls callback 10x.
for (var i = 0; i < 10; i++) {
    readFile('./sample.txt', function(err, data) {
        console.log(data);
    });
}

options is passed directly to lru-cache allowing you to set the max age, max items, and other behaviors of the LRU cache.

When options.stale is set to true the locking cache implements additional behavior to continue serving a stale item until the item has been refreshed in the background.

See also:

About

Read I/O locking using LRU cache


Languages

Language:JavaScript 100.0%