All API methods in the cache hook return a promise.
Returns a specific cache item by key.
- key [String]
- required:
true
- required:
RediBox.hooks.cache
.get('cat')
.then(data => {
console.log('Got a cat from cache', data);
});### SET
Adds a new cache item by key name.
-
key [String]
- required:
true
- required:
-
value [Object/Array/Primitive]
- required:
true
- required:
-
ttl [Number]
- required:
false - default:
60The time this particular item will be stored in the cache, in seconds.
- required:
RediBox.hooks.cache
.set('cat:fluffy', 'https://pbs.twimg.com/media/CYY44mYWMAATghb.jpg:small', 120)
.then(() => {
console.log('Set a fluffy cat in cache for two minutes');
});Deletes a specific cache item by key.
- key [String]
- required:
true
- required:
RediBox.hooks.cache
.get('cat')
.then(data => {
console.log('Got a cat from cache', data);
});Removes all, a specific, or a wildcard amount of items from the cache by key.
- key [String]
- required:
falseIf empty, will remove all cached items. To wildcard a filter, append a*onto the key.
- required:
// 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');
});Caches a promises response in cache, by key.
-
key [String]
- required:
true
- required:
-
promise [Promise]
- required:
trueA deferred promise, whose return/resolve value will be set in cache.
- required:
-
ttl [Number]
- required:
false - default:
60The time this particular item will be stored in the cache, in seconds.
- required:
-
skipCache [Bool]
- required:
false - default:
falseIftrue, the cache will be completley ignored.
- required:
const deferred = () => {
return User.find();
};
return Cache
.wrapPromise(
'external-api-data',
deferred,
120,
true,
);Caches a Waterline ORM query. The key is created automatically based on the model and query values.
-
query [Promise/Waterline]
- required:
true
- required:
-
ttl [Number]
- required:
false - default:
60The time this particular item will be stored in the cache, in seconds.
- required:
-
skipCache [Bool]
- required:
false - default:
falseIftrue, the cache will be completley ignored.
- required:
return Cache
.wrapWaterline(
User.find(),
120,
);