README
Stocache
stocache is a Redis/Memcache like cache for browser. it use local storage OR session storage for saving data
- no dependency
- fast and small (about 1k in gzip)
- auto manage storage limit
Installation
$ npm install stocache
OR
$ yarn add stocache
How to use
const cache = stocache()
arguments
First arguments: Scope
- default: stocache
const adminCache = stocache("Admin")
const userCache = stocache("User")
Second arguments: Storage Type
- default: localStorage
const cache = stocache("admin", "sessionStorage")
Third arguments: Exceptions
- default: False
const cache = stocache("admin", "localStorage", True)
Methods
set
return True if saved data otherwise False
cache.set(KEY, VALUE, TTL)
- KEY must be String
- TTL in second
- default is 60
get
return corresponding VALUE if KEY exist and not expired otherwise FALLBACK
cache.get(KEY, FALLBACK)
- FALLBACK default is False
unset
return True on success otherwise False
cache.unset(KEY)
has
return True if KEY exist and not expired otherwise False
cache.has(KEY)
flush
return True on success otherwise False
cache.flush(SCOPE)
- SCOPE default is stocache
keep
updating expire time
cache.keep(KEY, TTL)
- TTL default is 60