Skip to content

un-ts/yocto-ttl-cache

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date
Jul 16, 2022
Jul 17, 2022
Aug 22, 2022
Jul 16, 2022
Jul 10, 2022
Jul 12, 2022
Jul 10, 2022
Jul 10, 2022
Jul 16, 2022
Aug 22, 2022
Jul 10, 2022
Jul 10, 2022
Jul 10, 2022
Jul 16, 2022
Jul 10, 2022
Aug 22, 2022
Jul 10, 2022
Aug 22, 2022
Jul 10, 2022
Jul 10, 2022
Jul 12, 2022
Jul 10, 2022
Jul 16, 2022
Jul 10, 2022
Aug 22, 2022
Jul 12, 2022
Sep 4, 2024
Aug 29, 2024
Jul 10, 2022
Jul 10, 2022

Repository files navigation

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

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Backers

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Changelog

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

License

MIT © JounQin@1stG.me