@melchyore/adonis-cache
Version:
Cache package for AdonisJS V5
74 lines (73 loc) • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class CacheProvider {
constructor(app) {
this.app = app;
}
register() {
this.app.container.singleton('Adonis/Addons/Cache', () => {
const config = this.app.container.resolveBinding('Adonis/Core/Config').get('cache', {});
const CacheManager = require('../src/CacheManager').default;
return new CacheManager(this.app, config);
});
/* istanbul ignore next */
this.app.container.singleton('Adonis/Addons/Cache/Stores', () => {
return {
BaseCacheStore: require('../src/Stores/BaseStore').default,
TaggableStore: require('../src/Stores/TaggableStore').default
};
});
}
async boot() {
// IoC container is ready
this.registerViewHelper();
this.defineReplBindings();
}
async ready() {
// App is ready
}
async shutdown() {
// Cleanup, since app is going down
}
/**
* Define repl binding
*/
defineReplBindings() {
/**
* Do not register repl binding when not running in "repl"
* environment
*/
/* istanbul ignore next */
if (this.app.environment !== 'repl') {
return;
}
/**
* Define REPL bindings
*/
/* istanbul ignore next */
this.app.container.withBindings(['Adonis/Addons/Repl'], (Repl) => {
const { defineReplBindings } = require('../src/Bindings/Repl');
defineReplBindings(this.app, Repl);
});
}
/**
* Define view helper
*/
registerViewHelper() {
/**
* Do not register view helper when running in "test"
* environment
*/
if (this.app.environment !== 'repl') {
return;
}
/* istanbul ignore next */
this.app.container.withBindings(['Adonis/Core/Server', 'Adonis/Addons/Cache'], (Server, Cache) => {
Server.hooks.before(async (ctx) => {
ctx.view.share({ cache: Cache });
});
});
}
}
exports.default = CacheProvider;
CacheProvider.needsApplication = true;