26 lines
585 B
TypeScript
26 lines
585 B
TypeScript
import { RedisCache } from './providers/redis-cache';
|
|
import { MemoryCache } from './providers/memory-cache';
|
|
import type { CacheProvider, CacheOptions } from './types';
|
|
|
|
/**
|
|
* Factory for creating cache providers.
|
|
*
|
|
* @param type 'redis' | 'memory'
|
|
* @param options configuration for the cache
|
|
*/
|
|
export function createCache(
|
|
type: 'redis' | 'memory',
|
|
options: CacheOptions = {}
|
|
): CacheProvider {
|
|
if (type === 'redis') {
|
|
return new RedisCache(options);
|
|
}
|
|
return new MemoryCache(options);
|
|
}
|
|
|
|
export {
|
|
CacheProvider,
|
|
CacheOptions,
|
|
RedisCache,
|
|
MemoryCache
|
|
};
|