Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/segment-boneyard/proxy-cache
A proxying in-memory cache for node.
https://github.com/segment-boneyard/proxy-cache
Last synced: about 7 hours ago
JSON representation
A proxying in-memory cache for node.
- Host: GitHub
- URL: https://github.com/segment-boneyard/proxy-cache
- Owner: segment-boneyard
- Created: 2013-10-29T01:40:22.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-02-02T19:21:17.000Z (almost 9 years ago)
- Last Synced: 2024-04-09T16:31:13.766Z (7 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 7
- Watchers: 33
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# proxy-cache
A proxying in-memory cache for node.
## Installation
$ npm install segmentio/proxy-cache
## Examples
```js
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](https://github.com/isaacs/node-lru-cache#options) options. Here are the defaults:```js
{
max: 10000,
maxAge: ms('1m'),
stale: false,
peek: true, // peek by default so maxAge is honored
tombstone: true // save undefined values returned as well
}
```## License
```
WWWWWW||WWWWWW
W W W||W W W
||
( OO )__________
/ | \
/o o| MIT \
\___/||_||__||_|| *
|| || || ||
_||_|| _||_||
(__|__|(__|__|
```