UNPKG

adonis5-cache

Version:
55 lines (54 loc) 2.45 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const CacheManager_1 = __importDefault(require("../src/CacheManager")); const RedisStorage_1 = __importDefault(require("../src/CacheStorages/RedisStorage")); const InMemoryStorage_1 = __importDefault(require("../src/CacheStorages/InMemoryStorage")); const MemcachedStorage_1 = __importDefault(require("../src/CacheStorages/MemcachedStorage")); class AdonisCacheProvider { constructor(application) { this.application = application; this.container = application.container; } async register() { this.container.singleton('Adonis/Addons/Adonis5-Cache', () => { const eventEmitter = this.container.use('Adonis/Core/Event'); const config = this.container.use('Adonis/Core/Config'); return new CacheManager_1.default({ eventEmitter, config: config.get('cache'), }); }); } async boot() { const cache = this.container.use('Adonis/Addons/Adonis5-Cache'); const cacheConfig = this.container.use('Adonis/Core/Config').get('cache'); if (cacheConfig.enabledCacheStorages.includes('redis')) { this.registerRedisCacheStorage(cache); } if (cacheConfig.enabledCacheStorages.includes('in-memory')) { this.registerInMemoryCacheStorage(cache); } if (cacheConfig.enabledCacheStorages.includes('in-memory')) { this.registerInMemoryCacheStorage(cache); } if (cacheConfig.enabledCacheStorages.includes('memcached')) { this.registerMemcachedCacheStorage(cache); } } registerRedisCacheStorage(cache) { const redis = this.container.use('Adonis/Addons/Redis'); cache.registerStorage('redis', new RedisStorage_1.default(redis)); } registerInMemoryCacheStorage(cache) { cache.registerStorage('in-memory', new InMemoryStorage_1.default()); } registerMemcachedCacheStorage(cache) { const memcachedClient = this.container.use('Adonis/Addons/Adonis5-MemcachedClient'); cache.registerStorage('memcached', new MemcachedStorage_1.default(memcachedClient)); } } exports.default = AdonisCacheProvider; AdonisCacheProvider.needsApplication = true;