zstorage-node
the localStorage that has expired time, you can use it in NodeJS
Install
$ npm install zstorage-node --save
Test
$ git clone https://github.com/klren0312/localStorage_hasExpiration.git
$ cd localStorage_hasExpiration
$ git checkout feature/node
$ npm install
$ npm run test
Use
you can see example in
storage.test.js
const ZStorage = require('zstorage-node')
const Storage = new ZStorage('test.txt', '', '')
Storage.set('test', {t:1,b:2}, 5)
console.log('current,', Storage.get('test'))
setTimeout(() => console.log('after 5s,', Storage.get('test')), 5000)
Api
get (key)
get the value by key from localStorage
param:
key
return:
null (expired)
value (not expired)
set (key, value, expired_second)
set the localStorage, with key, value and expired_second(unit: s)
Tips: You'll not use JSON.stringify()
to stringify Object or Array
param:
key
value
expired_second
return
remove (key)
remove the value by key from localStorage
param:
key
return
clear ()
clear all values from localStorage