javascript - module exports property by reference -
i have cache class:
class cache { constructor() { this._cache = {}; } refresh(cb) { enums_db.find({key: {$in: ['country_list', 'supported_countries', 'country_dial']}}).exec((e, docs) => { _.each(docs, (doc) => { switch (doc.key) { case 'country_list': this._cache.country_list = doc.value; break case 'supported_countries': this._cache.supported_countries = doc.value; break; case 'country_dial': this._cache.country_dial = doc.value; break; } }) cb && cb() }) } init(cb) { this.refresh(cb) setinterval(() => { this.refresh() }, 3000) } } module.exports = new enums()
module.exports = new enums()
also, have enums file:
const cache = require('./utils/cache') module.exports = { country_list: cache.cache.country_list, supported_countries: cache.supported_countries, country_dial: cache.country_dial, other_enum: [] }
and print example file:
const {country_list} = require('../enums') setinterval(function () { console.log(country_list) }, 3000)
this way same values, if they're refreshed , edited in cahche class. i've seen if export cache, , user print as: cache.country_list work. how can solve it, print print country_list propery enums, , accessed ref cache file?
thanks.
Comments
Post a Comment