@cc-heart/storage-cache
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Storage Cache

Storage Cache is a library for scoping APIs stored in browser local storage, aimed at preventing conflicts when using APIs in the same origin environment.

Installation

You can install Storage Cache via npm:

npm install @cc-heart/storage-cache

Usage

Creating a StorageCache Instance

import { defineStorage } from '@cc-heart/storage-cache';

const { localStorageCache, sessionStorageCache } = new defineStorage('namespace');

set data:

localStorageCache.setItem('key', 'value');
localStorageCache.setItem('key', 'value', 1000) // set expiration time
localStorageCache.setItem('key', 'value', 'EX', 1000) // set expiration time in second

get data:

localStorageCache.getItem('key') // value

remove data:

localStorageCache.removeItem('key')

clean up all storage under the scope:

localStorageCache.clear()

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i @cc-heart/storage-cache

Weekly Downloads

2

Version

0.0.5

License

MIT

Unpacked Size

123 kB

Total Files

52

Last publish

Collaborators

  • cc-heart