import type { CacheFactoryInterface, CacheInterface } from '@cachehub/core'; import { CloudflareCache } from '../Cache'; import type { TypeCloudflareCacheConfig } from '../Type'; export class CloudflareCacheFactory implements CacheFactoryInterface { /** * Creates a cache based on the provided configuration. * * @param {TypeCloudflareCacheConfig} config - The configuration object for the cache provider. * @returns {CacheInterface} - A cache provider instance. * @throws {Error} - Throws an error when requested provider cache can't be created. */ public createCache(config: TypeCloudflareCacheConfig): CacheInterface { const getCache = config.CACHE_NAME ? async (): Promise => await (caches as any).open(config.CACHE_NAME) : async (): Promise => (caches as any).default; return new CloudflareCache(config.CACHE_BASE_URL, getCache); } }