5.0.6 • Published 6 years ago

loopback-cache-machine v5.0.6

Weekly downloads
199
License
-
Repository
github
Last release
6 years ago

loopback-cache-machine

Caching system for Loopback, maintained via GoogleCloud PubSub

Usage client side

In a boot script

// Instanciate with the app and tell it what model name to listen to
var cache = require('loopback-cache-machine')(app,
{
    type: 'client',
    serviceName: CACHE_CLIENT_NAME,
    projectId: GOOGLE_CLOUD_PROJECT_ID,
    modelsToWatch: [{modelName: 'Customer'}],
    //Optional event config
    eventConfig: {
        events: ['Order.create', 'Order.update', 'Order.delete'],
        //eventFn will trigger for all events
        eventFn: function(modelName, methodName, modelId, data, cb) {...}
    }
    //Optional readiness callback, res is intitial cached data on success
    onReady: function(err, res) { .... }
});

Then in the models you want to use cache

// Require the cache with options.serviceName
var cache = require('loopback-cache-machine')(app, {serviceName: CACHE_NAME});

// And boom you have access to cached data
var customer = cache.cached.Customer[_customer_id_];

Usage server side

In a boot script

// Instanciate with the app
var cacheServer = require('loopback-cache-machine')(app,
{
    type: 'server',
    serviceName: CACHE_SERVER_NAME,
    projectId: GOOGLE_CLOUD_PROJECT_ID,
    //Optional list of functions taking (modelName, methodName, instance, ctx) as arguments. If any return false, message will not be published
    filters: [filterFunction1, filterFunction2],
    //Optional readiness callback, res is true on success
    onReady: function(err, res) { .... }
});

Usage locally

In a boot script

// Instanciate with the app
var cacheServer = require('loopback-cache-machine')(app,
{
    type: 'local',
    projectId: GOOGLE_CLOUD_PROJECT_ID
    modelsToWatch: [{modelName: 'Customer'}],
    //Optional readiness callback, res is intitial cached data on success
    onReady: function(err, res) { .... }
});

Then in the models you want to use cache

// Require the cache with options.serviceName
var cache = require('loopback-cache-machine')(app, {serviceName: CACHE_NAME});

// And boom you have access to cached data
var customer = cache.cached.Customer[_customer_id_];

Notes

  • Multiple caches and cache types may exist on a single app instance, but only one per name.
  • The cache is not initialized and primed with data until called with a valid options.type (server/client/local).
  • process.env.NODE_ENV is required, as it is used to differentiate topic and subscription names by environment on Google PubSub.
5.0.6

6 years ago

5.0.5

6 years ago

5.0.4

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.0.26

6 years ago

4.0.25

6 years ago

4.0.24

6 years ago

4.0.23

6 years ago

4.0.22

6 years ago

4.0.21

6 years ago

4.0.20

6 years ago

4.0.19

6 years ago

4.0.18

6 years ago

4.0.17

6 years ago

4.0.16

6 years ago

4.0.15

7 years ago

4.0.14

7 years ago

4.0.13

7 years ago

4.0.12

7 years ago

4.0.11

7 years ago

4.0.10

7 years ago

4.0.9

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago