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" }
],
};
Last active
April 30, 2020 23:45
-
-
Save icebob/a69082b3078c8769f66de6c6dc4e56ba to your computer and use it in GitHub Desktop.
Cacher cleaner mixin for Moleculer DB service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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