New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

quick-cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quick-cache

Helper script for storing JavaScript objects in the localStorage, if available.

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Quick Cache

Script for storing JavaScript objects in the localStorage, if available. The script has a timeout feature that will return a null if the data has expired.

##Usage ####initialize

with 2s expiration and an error callback handler var cache = new QuickCache(2000, function(error){/*handle error*/});

with no expiration and an error callback handler var cache = new QuickCache(function(error){/*handle error*/});

with 2s expiration var cache = new QuickCache(2000);

with no expiration var cache = new QuickCache();

####store data

cache.set('terms',{a:'1',b:'2',c:'3'});

####retrieve data

var termData = cache.get('terms');

with the first cache variable above if you did not get the data within 2s it would return a null. on the second cache the data would be {a:'1',b:'2',c:'3'} because a timeout does not exist.

##Why Timeout? Fair enough. Lets say you have some data in a hybrid application. This data may change once a month or once a week. It's not really critical data, but you would like to check for it every once and a while.

\\create cache object to expire once a week
var colorCache = new QuickCache((1000 * 60 * 60 * 24 * 7));

\\try to get colors from cache
var colors = colorCache.get('colors');

\\if colors don't exist or are expired get the latest
if(!colors){
    //call external to get colors
    colors = getColors();
    //refresh the cache
    colorCache.set('colors',colors);
}

Keywords

javascript

FAQs

Package last updated on 31 May 2016

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