restructured libs to be more aligned with core components

This commit is contained in:
Boki 2025-06-23 19:51:48 -04:00
parent 947b1d748d
commit 0d1be9e3cb
50 changed files with 73 additions and 67 deletions

View file

@ -1,55 +0,0 @@
import { RedisCache } from './redis-cache';
import type { CacheOptions, CacheProvider } from './types';
// Cache instances registry to prevent multiple instances with same prefix
const cacheInstances = new Map<string, CacheProvider>();
/**
* Create a Redis cache instance with trading-optimized defaults
*/
export function createCache(options: CacheOptions): CacheProvider {
const defaultOptions: CacheOptions = {
keyPrefix: 'cache:',
ttl: 3600, // 1 hour default
enableMetrics: true,
shared: true, // Default to shared connections
...options,
};
// For shared connections, reuse cache instances with the same key prefix
if (defaultOptions.shared) {
const cacheKey = `${defaultOptions.keyPrefix}-${defaultOptions.ttl}`;
if (cacheInstances.has(cacheKey)) {
const cachedInstance = cacheInstances.get(cacheKey);
if (!cachedInstance) {
throw new Error(`Expected cache instance ${cacheKey} to exist`);
}
return cachedInstance;
}
const cache = new RedisCache(defaultOptions);
cacheInstances.set(cacheKey, cache);
return cache;
}
// For non-shared connections, always create new instances
return new RedisCache(defaultOptions);
}
// Export types and classes
export type {
CacheConfig,
CacheKey,
CacheOptions,
CacheProvider,
CacheStats,
RedisConfig,
SerializationOptions,
} from './types';
export { RedisConnectionManager } from './connection-manager';
export { CacheKeyGenerator } from './key-generator';
export { RedisCache } from './redis-cache';
export { NamespacedCache } from './namespaced-cache';
export { createNamespacedCache, isCacheAvailable } from './cache-factory';