New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

page-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

page-cache

Support you to store data when jump to other page, restore data when go back or jump to original page.

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
6
-25%
Maintainers
1
Weekly downloads
 
Created
Source

page-cache

Support you to store data when jump to other page, restore data when go back or jump to original page.

FEATURES

  • use SessionStorage in the default, support LocalStorage either(use store2)
  • only ESModule
  • support checkGoBack: restore if only goback to original page
  • support timeout, default 1h

USAGE

> npm i -S page-cache
import PageCache from 'page-cache';

const CACHE_PREFIX = 'CACHE_PREFIX';

const cache = new PageCache({
    prefix: CACHE_PREFIX,
    checkGoBack: true,
    timeout: 1000 * 60 * 60 * 24
});

// restore data when back to original page again
let {
    data1,
    data2 = 0
} = cache.restore(({data1 = {}} = {}) => data1 === 'xxx1'); // check if to restore

cache.set('data1', 'xxx');
setTimeout(() => {
    cache.set('data2', ++data2); // you could set anytime
    cache.set('data1', 'xxx1'); // or update anytime
    // don't worry about performance,
    // data will set to 'local/session storage' when page leaving
}, 1000);

Keywords

cache

FAQs

Package last updated on 15 Nov 2019

Related posts