User Tools

Site Tools


SIB Cache


The sib_cache is a module for caching data in the SIB. The cache module can listen to a setter topic which will update the cache according to a set of rules, and it will listen to a getter topic that will return cached data to the responseTopic of the calling message.


  • Listen to settopic
    • on message
      • if .custom.set run .custom.set on data
      • else merge the msg.value data into the cache object
  • Listen to gettopic
    • on message
      • if .custom.get run .custom.get on data
      • else get the msg.path object from the cache and return the data

Upon sending an empty string to the gettopic the entire cache will be returned. To clear the cache send an empty object to the settopic as msg.value.

Custom configuration

"use strict";
var CacheCustom = {
	_id: "cacheSample:1",
	_name: "SIB Cache sample",
	get: (cache, topic, msg, cb)=>{cb({data:123});},
	getsize: (cache, cb)=>{cb( cache.length );},
	gettopic: "SIB/CACHE/GET",
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
	mqtt: "mqtt://localhost",
	set: (cache, topic, msg, cb)=>{cache[0]=1;cb();},
	settopic: "SIB/CACHE/SET"
module.exports = CacheCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • get: Method to override the standard cache function for getting information from the cache
  • getsize: Method for getting the size of the cache, in case the standard cache function is overridden
  • gettopic: The topic to listen to for get statements
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • mqtt: The MQTT connection string for the internal MQTT transport
  • set: Method to override the standard cache function for setting information to the cache
  • settopic: The MQTT topic to subscribe to on the internal MQTT transport for setting information to the cache. If this is an array all the topics will be subscribed to.
sib/cache.txt · Last modified: 2019/03/02 17:35 by hubbe