Skip to content

Instantly share code, notes, and snippets.

@icebob
Last active April 30, 2020 23:45
Show Gist options
  • Save icebob/a69082b3078c8769f66de6c6dc4e56ba to your computer and use it in GitHub Desktop.
Save icebob/a69082b3078c8769f66de6c6dc4e56ba to your computer and use it in GitHub Desktop.
Cacher cleaner mixin for Moleculer DB service

Cache cleaner mixin for Moleculer DB service

Usage

const DbService	= require("moleculer-db");

module.exports = {
    name: "boards",

    mixins: [
        DbService,
        CacheCleaner([
            // Itself because it can be run multiple instances
            "cache.clean.boards",
            "cache.clean.accounts"
            // Add all dependent services
        ]),
    ],

    dependencies: [
        { name: "accounts" }
    ],

};
"use strict";
module.exports = function(eventNames) {
const events = {};
eventNames.forEach(name => {
events[name] = function() {
if (this.broker.cacher) {
this.logger.debug(`Clear local '${this.name}' cache`);
this.broker.cacher.clean(`${this.name}.*`);
}
};
});
return {
events
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment