storage-cache is a utility library designed to enhance the native localStorage and sessionStorage in browsers. With this library, you can manage stored data more flexibly, avoid interference between different data, and easily set expiration times for your data.
- Storage scope isolation
- Support for setting expiration times
npm install @cc-heart/storage-cacheCreate a storage-cache 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 secondGet data
localStorageCache.getItem('key') // valueRemove data
localStorageCache.removeItem('key')Clear all data within the storage scope
localStorageCache.clear()This project is licensed under the MIT License.