This commit is contained in:
Boki 2025-06-20 23:11:28 -04:00
parent 2c6c2f8e44
commit 830b9e94a1
5 changed files with 184 additions and 52 deletions

View file

@ -1,5 +1,5 @@
import { RedisCache } from './redis-cache';
import type { CacheOptions, CacheProvider, RedisConfig } from './types';
import type { CacheOptions, CacheProvider } from './types';
// Cache instances registry to prevent multiple instances with same prefix
const cacheInstances = new Map<string, CacheProvider>();
@ -37,62 +37,14 @@ export function createCache(options: CacheOptions): CacheProvider {
return new RedisCache(defaultOptions);
}
/**
* Create a cache instance for trading data
*/
export function createTradingCache(redisConfig: RedisConfig, options?: Partial<Omit<CacheOptions, 'redisConfig'>>): CacheProvider {
return createCache({
keyPrefix: 'trading:',
ttl: 3600, // 1 hour default
enableMetrics: true,
shared: true,
...options,
redisConfig,
});
}
/**
* Create a cache for market data with shorter TTL
*/
export function createMarketDataCache(redisConfig: RedisConfig, options?: Partial<Omit<CacheOptions, 'redisConfig'>>): CacheProvider {
return createCache({
keyPrefix: 'market:',
ttl: 300, // 5 minutes for market data
enableMetrics: true,
shared: true,
...options,
redisConfig,
});
}
/**
* Create a cache for indicators with longer TTL
*/
export function createIndicatorCache(redisConfig: RedisConfig, options?: Partial<Omit<CacheOptions, 'redisConfig'>>): CacheProvider {
return createCache({
keyPrefix: 'indicators:',
ttl: 1800, // 30 minutes for indicators
enableMetrics: true,
shared: true,
...options,
redisConfig,
});
}
// Export types and classes
export type {
CacheProvider,
CacheOptions,
CacheConfig,
CacheStats,
CacheKey,
SerializationOptions,
RedisConfig,
CacheConfig, CacheKey, CacheOptions, CacheProvider, CacheStats, RedisConfig, SerializationOptions
} from './types';
export { RedisCache } from './redis-cache';
export { RedisConnectionManager } from './connection-manager';
export { CacheKeyGenerator } from './key-generator';
export { RedisCache } from './redis-cache';
// Default export for convenience
export default createCache;