🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

browser-cache-store

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-cache-store

A simple cache store that uses IndexedDB (falls back to localStorage if IndexedDB is not available).

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
5
-68.75%
Maintainers
0
Weekly downloads
 
Created
Source

browser-cache-store

npm version install size npm downloads

A simple cache store that uses IndexedDB (falls back to localStorage if IndexedDB is not available).

This library offers the following features:

  • Every operation on the cache store is atomic.
  • Users can retrieve the previous value associated with a key and replace it with a new value in a single atomic operation.

Installation:

npm i browser-cache-store

Examples:

import { createCacheStore } from 'browser-cache-store'

const store = createCacheStore('the_store_name')

// put value
store
  .put('counter', (prev) => (prev || 0) + 1)
  .then((res) => {
    console.log(res.prev)
    console.log(res.next)
  })

// set value
store.set('key', 'value').then(() => {
  console.log('set')
})

// get value
store.get('key').then((value) => {
  console.log(value)
})

// remove key
store.remove('key').then(() => {
  console.log('removed')
})

// remove all
store.clear().then(() => {
  console.log('cleared')
})

Keywords

indexedDB

FAQs

Package last updated on 01 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts