Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dalirnet/stocache
Redis like cache for browser
https://github.com/dalirnet/stocache
cache javascript localstorage sessionstorage
Last synced: 3 days ago
JSON representation
Redis like cache for browser
- Host: GitHub
- URL: https://github.com/dalirnet/stocache
- Owner: dalirnet
- Created: 2020-12-25T20:22:46.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T12:13:59.000Z (over 3 years ago)
- Last Synced: 2024-10-13T15:55:57.549Z (about 1 month ago)
- Topics: cache, javascript, localstorage, sessionstorage
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/stocache
- Size: 215 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
```sh
$ npm install stocache
```OR
```sh
$ yarn add stocache
```### How to use
```javascript
const cache = stocache()
```#### arguments
First arguments: Scope
- default: stocache
```javascript
const adminCache = stocache("Admin")
``````javascript
const userCache = stocache("User")
```Second arguments: Storage Type
- default: localStorage
```javascript
const cache = stocache("admin", "sessionStorage")
```Third arguments: Exceptions
- default: False
```javascript
const cache = stocache("admin", "localStorage", True)
```#### Methods
#### set
return True if saved data otherwise False
```javascript
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
```javascript
cache.get(KEY, FALLBACK)
```- FALLBACK default is False
#### unset
return True on success otherwise False
```javascript
cache.unset(KEY)
```#### has
return True if KEY exist and not expired otherwise False
```javascript
cache.has(KEY)
```#### flush
return True on success otherwise False
```javascript
cache.flush(SCOPE)
```- SCOPE default is stocache
#### keep
updating expire time
```javascript
cache.keep(KEY, TTL)
```- TTL default is 60