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
Usage
Complete API Documentation.
import Cachely from 'cachely'
let fetches = 0
const cachely = new Cachely({
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)
Install
- Install:
npm install --save cachely
- Import:
import pkg from ('cachely')
- Require:
const pkg = require('cachely').default
<script type="module">
import pkg from '//cdn.skypack.dev/cachely@^6.0.0'
</script>
<script type="module">
import pkg from '//unpkg.com/cachely@^6.0.0'
</script>
<script type="module">
import pkg from '//dev.jspm.io/cachely@6.0.0'
</script>
This package is published with the following editions:
cachely
aliases cachely/index.cjs
which uses the Editions Autoloader to automatically select the correct edition for the consumer's environmentcachely/source/index.ts
is TypeScript source code with Import for modulescachely/edition-browsers/index.js
is TypeScript compiled against ES2022 for web browsers with Import for modulescachely/edition-es2022/index.js
is TypeScript compiled against ES2022 for Node.js 12 || 14 || 16 || 18 || 20 || 21 with Require for modulescachely/edition-es2021/index.js
is TypeScript compiled against ES2021 for Node.js 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modulescachely/edition-es2016/index.js
is TypeScript compiled against ES2016 for Node.js 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modulescachely/edition-es2022-esm/index.js
is TypeScript compiled against ES2022 for Node.js 12 || 14 || 16 || 18 || 20 || 21 with Import for modules
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: