šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

localstorage-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-cache

storage

1.0.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

localstorage-cache

storage

Installation

In a browser:

<script src="localstorage-cache.js"></script>

Using npm:

$ npm i -g localstorage-cache
$ npm i --save localstorage-cache

Usage:

import LocalStorageCache from 'localstorage-cache';

/*
 * Set cache size: 2 * 1024KB(2MB)
 * set cache strategy: LRU / LFU;
 */
const storageCache = new LocalStorageCache(2 * 1024, 'LRU'); //

/**
 * set cache, and unit of expire is second.
 * @param {string/number} key
 * @param {any} value
 * @param {number} [expire]
 * @param {string} [charset]
 */
storageCache.setCache('name', 'lzwaiwai', 'utf8').setCache('age', 18);
storageCache.setCache('work', 'IT', 24 * 60 * 60);

/**
 * get cache by key.
 * @param {string/number} key
 * @returns
 */
const cacheWork = storageCache.getCache('work');
console.log(cacheWork);

/**
 * delete cache by key.
 * @param {string/number} key
 */
storageCache.deleteCache('age');

/**
 * delete all cache.
 */
storageCache.clearCache();
...

FAQs

Package last updated on 28 Apr 2018

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