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
import pkg from 'https://unpkg.com/cachely@^6.8.0/edition-deno/index.ts'
<script type="module">
import pkg from '//cdn.skypack.dev/cachely@^6.8.0'
</script>
<script type="module">
import pkg from '//unpkg.com/cachely@^6.8.0'
</script>
<script type="module">
import pkg from '//dev.jspm.io/cachely@6.8.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-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 modulescachely/edition-types/index.d.ts
is TypeScript compiled Types with Import for modulescachely/edition-deno/index.ts
is TypeScript source code made to be compatible with Deno
History
Discover the release history by heading on over to the HISTORY.md
file.
Backers
Code
Discover how to contribute via the CONTRIBUTING.md
file.
Authors
Maintainers
Contributors
Finances
Donors
License
Unless stated otherwise all works are:
and licensed under: