moleculerjs / moleculerjs/rfcs

Service-level cacher

Open
#4 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Change: Minor Module: Cacher Module: Core Stage: 2
Dominant language
No language data
Stars
2
Forks
4
PR merge metrics
No merged PRs in 30d

Description

  • 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the broker-level cacher configuration, the service schema used by createService, and how action-level cache settings are handled. Define the service-level behavior for the MemoryLRU and Redis examples, including how different services select implementations; the issue currently provides no files, tests, or completed design sections to identify a concrete validation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.