Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yuri2peter/yl-cache
A simple k-v cache for front end.
https://github.com/yuri2peter/yl-cache
Last synced: about 2 months ago
JSON representation
A simple k-v cache for front end.
- Host: GitHub
- URL: https://github.com/yuri2peter/yl-cache
- Owner: yuri2peter
- License: mit
- Created: 2018-11-08T09:49:21.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-28T01:52:50.000Z (about 6 years ago)
- Last Synced: 2024-04-26T08:22:24.003Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yl-cache
A simple k-v cache for front end.
# How to Use
```javascript
import YlCache from 'yl-cache';
const c = new YlCache('cache-key');
c.set('a', 1);
c.set('b', 2);
c.set('c', 3, YlCache.ONE_HOUR);
console.log(c.get('a'), c.get('b'), c.get('c'));
```
# API## constructor(string namespace)
@param namespace Set cache namespace. Using same namespace to attach same cache data.
@return YlCache
## set(string key, mixed value, int expire = 0)
Set cache data.
@param key Cache key
@param value Cache value
@param expire Expire time(s)
## has(string key)
Check if cache exist or not.
@param key Cache key
@return bool Returns true if cache exists
## get(string key, mixed defaultValue = null)
Get cache data.
@param key Cache key
@param defaultValue Return this value if cache is not exists
@return mixed Cache value
## pop(string key, mixed defaultValue = null)
Same as method get but delete the cache after read.
remove(string key)
Remove a cache.
@param key Cache key