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
$ npm install stocache
OR
$ yarn add stocache
const cache = stocache()
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)
return True if saved data otherwise False
cache.set(KEY, VALUE, TTL)
- KEY must be String
- TTL in second
- default is 60
return corresponding VALUE if KEY exist and not expired otherwise FALLBACK
cache.get(KEY, FALLBACK)
- FALLBACK default is False
return True on success otherwise False
cache.unset(KEY)
return True if KEY exist and not expired otherwise False
cache.has(KEY)
return True on success otherwise False
cache.flush(SCOPE)
- SCOPE default is stocache
updating expire time
cache.keep(KEY, TTL)
- TTL default is 60