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
});
let {
data1,
data2 = 0
} = cache.restore(({data1 = {}} = {}) => data1 === 'xxx1');
cache.set('data1', 'xxx');
setTimeout(() => {
cache.set('data2', ++data2);
cache.set('data1', 'xxx1');
}, 1000);