0.1.2 • Published 3 years ago

yocto-ttl-cache v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

yocto-ttl-cache

GitHub Actions Codecov Language grade: JavaScript type-coverage npm GitHub Release

Conventional Commits Renovate enabled JavaScript Style Guide Code Style: Prettier changesets

The smallest and fastest TTL cache implementation in JavaScript

TOC

Usage

Install

# pnpm
pnpm add yocto-ttl-cache

# yarn
yarn add yocto-ttl-cache

# npm
npm i yocto-ttl-cache

API

import { TTLCache } from 'yocto-ttl-cache' // only named export is supported

const cache = new TTLCache(1000) // the `ttl` option of `constructor` is `1000` by default

cache.get('key') // `undefined`
cache.get('key', () => 'value') // get with `setter`, `'value'`
cache.get('key', () => 'unused') // `'value'` is not stale

cache.set('key', 'newValue')
cache.get('key') // `'newValue'`

setTimeout(() => {
  cache.get('key') // `undefined`, stale after `ttl`
}, 1000)

Sponsors

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Backers

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG.me

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago