cachely
A tiny wrapper that sits around your request function that caches its data for a specified duration, provides updates as requested rather than polling each interval
Install
- Install:
npm install --save cachely
- Require:
require('cachely')
<script type="module">
import * as pkg from '//dev.jspm.io/cachely'
</script>
This package is published with the following editions:
cachely
aliases cachely/source/index.js
cachely/source/index.js
is esnext source code with require for modulescachely/edition-browsers/index.js
is esnext compiled for browsers with require for modules
This project provides its type information via inline JSDoc Comments. To make use of this in TypeScript, set your maxNodeModuleJsDepth
compiler option to 5
or thereabouts. You can accomlish this via your tsconfig.json
file like so:
{
"compilerOptions": {
"maxNodeModuleJsDepth": 5
}
}
Usage
API Documentation.
let fetches = 0
const cachely = require('cachely').create({
retrieve () {
return new Promise(function (resolve) {
setTimeout(() => resolve(++fetches), 1000)
})
},
duration: 2000,
log: console.log
})
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after one second as specified in our method, the result data should still be 1:'))
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after a tiny delay this will be from cache, the result data should still be 1:'))
setTimeout(function () {
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after one second as specified in our method, the result data should be 2, as it was our second fetch:'))
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after a tiny delay this will be from cache, the result data should still be 2:'))
cachely.invalidate()
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after one second as specified in our method, the result data should be 3, as it was our third fetch:'))
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after a tiny delay this will be from cache, the result data should still be 3:'))
}, 3000)
History
Discover the release history by heading on over to the HISTORY.md
file.
Contribute
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
Backers
Maintainers
These amazing people are maintaining this project:
No sponsors yet! Will you be the first?
Contributors
These amazing people have contributed code to this project:
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
License
Unless stated otherwise all works are:
and licensed under: