cache-chunk-store
Version:
In-memory LRU cache for abstract-chunk-store compliant stores
57 lines (41 loc) • 1.93 kB
Markdown
//img.shields.io/github/workflow/status/feross/cache-chunk-store/ci/master
[ ]: https://github.com/feross/cache-chunk-store/actions
[ ]: https://img.shields.io/npm/v/cache-chunk-store.svg
[ ]: https://npmjs.org/package/cache-chunk-store
[ ]: https://img.shields.io/npm/dm/cache-chunk-store.svg
[ ]: https://npmjs.org/package/cache-chunk-store
[ ]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[ ]: https://standardjs.com
[](https://github.com/mafintosh/abstract-chunk-store)
This caches the results of `store.get()` calls using
[`lru`](https://www.npmjs.com/package/lru). See the `lru` docs for the
full list of configuration options.
```
npm install cache-chunk-store
```
``` js
const CacheChunkStore = require('cache-chunk-store')
const FSChunkStore = require('fs-chunk-store') // any chunk store will work
const store = new CacheChunkStore(new FSChunkStore(10), {
// options are passed through to `lru-cache`
max: 100 // maximum cache size (this is probably the only option you need)
})
store.put(0, new Buffer('abc'), err => {
if (err) throw err
store.get(0, (err, data) => {
if (err) throw err
console.log(data)
// this will be super fast because it's cached in memory!
store.get(0, (err, data) => {
if (err) throw err
console.log(data)
})
})
})
```
MIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org).
[ ]: https: