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
- Use:
require('cachely')
- Install:
npm install --save cachely
- Use:
require('cachely')
- CDN URL:
//wzrd.in/bundle/cachely@1.0.1
- Install:
ender add cachely
- Use:
require('cachely')
Usage
let fetches = 0
const cachely = require('cachely').create({
method: function (next) {
setTimeout(function () {
next(null, ++fetches)
}, 1000)
},
duration: 2000,
log: console.log
})
cachely.request(function (err, data) {
console.log('after one second as specified in our method, the result data should still be 1:', data, err)
})
cachely.request(function (err, data) {
console.log('after a tiny delay this will be from cache, the result data should still be 1:', data, err)
})
setTimeout(function () {
cachely.request(function (err, data) {
console.log('after one second as specified in our method, the result data should be 2, as it was our second fetch:', data, err)
})
cachely.request(function (err, data) {
console.log('after a tiny delay this will be from cache, the result data should still be 2:', data, err)
})
cachely.invalidate()
cachely.request(function (err, data) {
console.log('after one second as specified in our method, the result data should be 3, as it was our third fetch:', data, err)
})
cachely.request(function (err, data) {
console.log('after a tiny delay this will be from cache, the result data should still be 3:', data, err)
})
}, 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: