Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/redibox/cache
Redis as a cache layer made simple.
https://github.com/redibox/cache
cache get hooks nodejs promise redibox redis sails set waterline
Last synced: about 1 month ago
JSON representation
Redis as a cache layer made simple.
- Host: GitHub
- URL: https://github.com/redibox/cache
- Owner: redibox
- License: mit
- Created: 2016-04-27T22:47:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-06T11:18:01.000Z (almost 8 years ago)
- Last Synced: 2024-10-02T04:43:10.931Z (about 1 month ago)
- Topics: cache, get, hooks, nodejs, promise, redibox, redis, sails, set, waterline
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Coverage Status](https://coveralls.io/repos/github/redibox/cache/badge.svg?branch=master)](https://coveralls.io/github/redibox/cache?branch=master)
![Downloads](https://img.shields.io/npm/dt/redibox-hook-cache.svg)
[![npm version](https://img.shields.io/npm/v/redibox-hook-cache.svg)](https://www.npmjs.com/package/redibox-hook-cache)
[![dependencies](https://img.shields.io/david/redibox/cache.svg)](https://david-dm.org/redibox/cache)
[![build](https://travis-ci.org/redibox/cache.svg)](https://travis-ci.org/redibox/cache)
[![License](https://img.shields.io/npm/l/redibox-hook-cache.svg)](/LICENSE)## RediBox Cache
Cache any data quickly and easily in Redis. Caching data is important to most applications. This hook handles various common requirements for caching data, specifically in Redis.
### Installation
First ensure you have [RediBox](https://github.com/redibox/core) installed.
Install Schedule via npm:
`npm install redibox-hook-cache --save`
### Usage
#### Configure cache
> This hook will still work without setting any configuration options.
Within your `redibox` config, we'll setup a new `cache` object containing our configiration options:
- **enabled** [Boolean]
- default: `true`
If disabled will by-pass any cached data.
- **defaultTTL** [Number]
- default: `60`
In seconds, if no time to live (TTL) is specified, this is how long items to live in the cache for.
- **keyPrefix** [String]
- default: `cache`
The namespace to store the cached items in Redis under. Shouldn't usually need changing.#### Basic API
##### GET
```javascript
// Get data by key from the cache
RediBox.hooks.cache.get('cat').then(data => {
console.log('Got a cat from cache', data);
});
```##### SET
```javascript
// Set data by key in the cache
RediBox.hooks.cache.set('cat:fluffy', 'https://pbs.twimg.com/media/CYY44mYWMAATghb.jpg:small').then(() => {
console.log('Set a fluffy cat in cache');
});
```##### DEL
```javascript
// Delete an item by key in the cache
RediBox.hooks.cache.del('cat').then(data => {
console.log('Deleted item');
});
```##### CLEAR
```javascript
// Delete all items in cache
RediBox.hooks.cache.clear().then(data => {
console.log('Clear all data in cache');
});// Delete all matching wildcard items in cache
RediBox.hooks.cache.clear('cat:fluffy:*').then(data => {
console.log('Clear wildcard data from cache');
});
```### Advanced Usage
- [API](https://github.com/redibox/cache/blob/master/docs/api.md)
- [Caching Async Data](https://github.com/redibox/cache/blob/master/docs/caching-async-data.md)### License
MIT