@cc-heart/storage-cache
v0.0.7
Published
a localStorage cache implementation
Downloads
8
Maintainers
Readme
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 } = 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.