Redis cache mixin for LoopBack
loopback-mixin-cache adds easy to use redis caching to any of your models.
Installation
$ npm i loopback-mixin-cache --save
Config
Server Config
With loopback-boot@v2.8.0 mixinSources have been implemented in a way which allows for loading this mixin without changes to the server.js file previously required. Just add "../node_modules/loopback-mixin-cache"
to the mixins
property of your server/model-config.json
.
{
"_meta": {
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-mixin-cache",
"../common/mixins"
]
}
}
Model Config
To use with your models just add Cache: true
to mixins
in your model config and the default options will be used:
{
"name": "Model",
"properties": {
"name": {
"type": "string",
}
},
"mixins": {
"Cache": true
}
...
"mixins": {
"Cache": {
"ttl": 30
}
}
}
Global Config
It is also possible to configure the mixin globally in your config.json
. Just add cache
and use the same options as with the model above:
{
"cache": {
"ttl": 30
}
}
ToDo and ideas
License
MIT
Changelog
v0.3.0
- Remove babel
- min. node version is now 8.x.x
v0.2.0
v0.1.0