Skip to content
 
 

Latest commit

 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages