loopback-mixin-cache adds easy to use redis caching to any of your models.
$ npm i loopback-mixin-cache --save
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/lib"
to the mixins
property of your server/model-config.json
.
{
"_meta": {
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-mixin-cache/lib",
"../common/mixins"
]
}
}
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
}
...
// you can also overide the default values:
"mixins": {
"Cache": {
"ttl": 30 // time to live (how long an item is being cached), default: 120
}
}
}
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 // time to live (how long an item is being cached), default: 120
}
}
- optimize cache keys
- add override parameter (e.g. ?noCache=true)
- add better usage documentation to this readme
- find better solution for searching and deleting cached items
- add response headers with information about the cache (environment agnostic)
- Initial stable version