Skip to content

magicdice/proxy-cache

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proxy-cache

A proxying in-memory cache for node.

Installation

$ npm install segmentio/proxy-cache

Examples

var DB = require('db');
var cache = require('proxy-cache');

var db = new DB();
db.getUserById('id', function (err, user) {
  // fetches `user` from the db
});

db = cache(new DB(), ['getUserById']);
db.getUserById('id', function (err, user) {
  // fetches the user from the db 
  // and caches it in memory as `getUserById:id`
  db.getUserById('id', function (err, user) {
    // this lookup fetches `user` directly the from the cache
  });
});

API

.cache(instance, methods, options)

Generate a proxying cache, with all properties of instance fully proxied, and all instance methods wrapped with a cache. You can also pass in optional options, which line up exactly with isaacs/node-lru-cache options. Here are the defaults:

{
  max    : 10000,
  maxAge : ms('1m'),
  stale  : false,
  peek   : true // peek by default so maxAge is honored.
}

License

WWWWWW||WWWWWW
 W W W||W W W
      ||
    ( OO )__________
     /  |           \
    /o o|    MIT     \
    \___/||_||__||_|| *
         || ||  || ||
        _||_|| _||_||
       (__|__|(__|__|

About

A proxying in-memory cache for node.

Resources

Stars

Watchers

Forks

Packages

No packages published