@consenlabs-fe/memory-cache
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Memory Cache

key-value pair cache tool.

Features

  • Multiple environment support
  • Stored in memory only
  • Extremely small size (<1kb)
  • No side effects

Compatibility

  • Browser: FF 45+, Safari 9+, Chrome 42+
  • Browser (low version): Add class polyfill from Babel or core-js
  • NodeJS: Full support
  • React Native: Full support

Guide

Install

  • Run npm i @consenlabs-fe/memory-cache.
  • ESM: import MemoryCache from '@consenlabs-fe/memory-cache'
  • CJS (NodeJS): const MemoryCache require('@consenlabs-fe/memory-cache')

Examples

1. Get and Set

const cache = new MemoryCache('my-caches')

cache.setItem('name', 'witt')
cache.getItem('name') // -> 'witt'

2. Remove and Clean

const cache = new MemoryCache('my-caches')

cache.setItem('name', 'witt')
cache.setItem('location', 'china')

cache.removeItem('name')
cache.getItem('name') // -> null
cache.getItem('location') // -> 'china'

cache.cleanAll()
cache.getItem('location') // -> null

3. Expiration

const cache = new MemoryCache('my-caches', { maxAge: 100 })

cache.setItem('name', 'witt')
cache.getItem('name') // -> 'witt'

setTimeout(() => {
  cache.getItem('name') // -> null
}, 200)

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @consenlabs-fe/memory-cache

Weekly Downloads

67

Version

0.1.0

License

MIT

Unpacked Size

8.76 kB

Total Files

9

Last publish

Collaborators

  • xwartz
  • younccat
  • xuneal