/** * Cache Manager Module * * Provides intelligent caching for API responses and computed values. * * Usage: * - Add data-module="cache-manager" to enable global cache manager * - Or import and use directly: import { CacheManager } from './modules/cache-manager/index.js' * * Features: * - Memory cache * - IndexedDB cache * - Cache invalidation strategies * - Cache warming * - Cache analytics * - Integration with RequestDeduplicator */ import { Logger } from '../../core/logger.js'; import { CacheManager, CacheStrategy } from './CacheManager.js'; import { getStrategyForUseCase } from './CacheStrategy.js'; const CacheManagerModule = { name: 'cache-manager', cacheManager: null, init(config = {}, state = null) { Logger.info('[CacheManagerModule] Module initialized'); // Create cache manager this.cacheManager = CacheManager.create(config); // Expose globally for easy access if (typeof window !== 'undefined') { window.CacheManager = this.cacheManager; window.CacheStrategy = CacheStrategy; } return this; }, /** * Get cache manager instance */ getCacheManager() { return this.cacheManager || CacheManager.create(); }, /** * Get value from cache */ async get(key, options = {}) { const cache = this.getCacheManager(); return await cache.get(key, options); }, /** * Set value in cache */ async set(key, value, options = {}) { const cache = this.getCacheManager(); return await cache.set(key, value, options); }, /** * Get or compute value */ async getOrSet(key, computeFn, options = {}) { const cache = this.getCacheManager(); return await cache.getOrSet(key, computeFn, options); }, destroy() { if (this.cacheManager) { this.cacheManager.destroy(); this.cacheManager = null; } if (typeof window !== 'undefined') { delete window.CacheManager; delete window.CacheStrategy; } Logger.info('[CacheManagerModule] Module destroyed'); } }; // Export for direct usage export { CacheManager, CacheStrategy, getStrategyForUseCase }; // Export as default for module system export default CacheManagerModule; // Export init function for module system export const init = CacheManagerModule.init.bind(CacheManagerModule);