Caching

Weave has a built-in caching provider to cache the responses of services. Currently there are adapters for In-Memory and REDIS as storage backends.

Caching example

    const { Weave } = require('@weave-js/core')

    // Create broker
    const broker = Weave({
        cacher: true
    })

    // Create a service
    broker.createService({
        name: 'order',
        actions: {
            list: {
                cache: true, 
                handler(ctx) {
                    this.log.info('Handler called!')
                    return [
                        { id: 1, sum: 123 },
                        { id: 2, sum: 456 }
                    ]
                }
            }
        }
    });

    broker.start()
        .then(() => {
            // No cached result found, so call the handler.
            return broker.call('order.list').then(result => broker.log.info('Orders found:', result.length));
        })
        .then(() => {
            // Cached result found. Return the cached result.
            return broker.call("user.list").then(result => broker.log.info('Cached orders found:', res.length));
        });

Built-in cachers

Call started event

todo

Call finished event

event