- Start Date: 2020-03-08
- Target Version: 0.14
- Reference Issues:
- Implementation PR:
Summary
We should add a new service-level cacher solution besides broker-based cacher. It can be useful when you don't want to use caching in all services, only just a few. In this case, you don't define cacher in broker options but in service schema instead.
Nevertheless, you can use different cacher implementations for different services.
Basic example
// Create broker
const broker = new ServiceBroker({
cacher: false
});
broker.createService({
name: "greeter",
// Service-level LRU cacher
cacher: {
type: "MemoryLRU",
options: {
max: 100,
ttl: 3
}
},
actions: {
hello: {
cache: true,
handler(ctx) {
return `Hello ${ctx.params.name}`;
}
}
}
});
broker.createService({
name: "products",
// Service-level Redis cacher
cacher: {
type: "Redis",
options: {
ttl: 30
}
},
actions: {
list: {
cache: true,
handler(ctx) {
return [];
}
}
}
});
Detailed design
Drawbacks
Alternatives
Adoption strategy
Unresolved questions
Summary
We should add a new service-level cacher solution besides broker-based cacher. It can be useful when you don't want to use caching in all services, only just a few. In this case, you don't define
cacherin broker options but in service schema instead.Nevertheless, you can use different cacher implementations for different services.
Basic example
Detailed design
Drawbacks
Alternatives
Adoption strategy
Unresolved questions