Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxcnunes/promise-async-cache
Simple lib to cache data through async load process.
https://github.com/maxcnunes/promise-async-cache
Last synced: about 1 month ago
JSON representation
Simple lib to cache data through async load process.
- Host: GitHub
- URL: https://github.com/maxcnunes/promise-async-cache
- Owner: maxcnunes
- License: mit
- Created: 2015-07-27T01:50:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-27T03:19:55.000Z (over 9 years ago)
- Last Synced: 2024-10-18T07:23:19.960Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promise-async-cache
[![Build Status](https://travis-ci.org/maxcnunes/promise-async-cache.svg?branch=master)](https://travis-ci.org/maxcnunes/promise-async-cache)
[![npm version](https://badge.fury.io/js/promise-async-cache.svg)](http://badge.fury.io/js/promise-async-cache)> Thanks [@esnunes](https://github.com/esnunes) for the initial implementation :)
## Installation
Install via npm:
```bash
$ npm install promise-async-cache
```## Usage
```js
// the example uses es6 but it works with es5 as well
import PromiseAsyncCache from 'promise-async-cache';// loading value into the cache
const cache = new PromiseAsyncCache({
load (key) {
// load async data
// then return a promise with the value to be cached
}
});// getting value from the cache
cache.get(key).then(value => /* ... */);
```### Extra arguments
Is possible passing extra arguments to the `load` function through the `get` function:
```js
const cache = new PromiseAsyncCache({
load (key, myOtherObject) { /* ... */ }
});cache.get(key, myOtherObject).then(value => /* ... */);
```It is required to use [editorconfig](http://editorconfig.org/) and please write and run specs before pushing any changes:
```js
npm test
```## License
Copyright (c) 2015 Max Claus Nunes. This software is licensed under the [MIT License](http://raw.github.com/maxcnunes/promise-async-cache/master/LICENSE).