commit 2 refactor
This commit is contained in:
parent
588f666943
commit
32e43c9243
310 changed files with 33318 additions and 31189 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { createCache, type CacheProvider, type CacheStats } from '@stock-bot/cache';
|
||||
import type { LoggerLike } from '@stock-bot/logger';
|
||||
import { generateCachePrefix } from './service-utils';
|
||||
import type { RedisConfig } from './types';
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ export class ServiceCache implements CacheProvider {
|
|||
serviceName: string,
|
||||
redisConfig: RedisConfig,
|
||||
isGlobalCache: boolean = false,
|
||||
logger?: any
|
||||
logger?: LoggerLike
|
||||
) {
|
||||
// Determine Redis DB and prefix
|
||||
let db: number;
|
||||
|
|
@ -45,11 +46,11 @@ export class ServiceCache implements CacheProvider {
|
|||
}
|
||||
|
||||
// Implement CacheProvider interface
|
||||
async get<T = any>(key: string): Promise<T | null> {
|
||||
async get<T = unknown>(key: string): Promise<T | null> {
|
||||
return this.cache.get<T>(key);
|
||||
}
|
||||
|
||||
async set<T = any>(
|
||||
async set<T = unknown>(
|
||||
key: string,
|
||||
value: T,
|
||||
options?:
|
||||
|
|
@ -98,7 +99,7 @@ export class ServiceCache implements CacheProvider {
|
|||
}
|
||||
|
||||
// Enhanced cache methods (delegate to underlying cache if available)
|
||||
async update<T = any>(key: string, value: T): Promise<T | null> {
|
||||
async update<T = unknown>(key: string, value: T): Promise<T | null> {
|
||||
if (this.cache.update) {
|
||||
return this.cache.update(key, value);
|
||||
}
|
||||
|
|
@ -106,7 +107,7 @@ export class ServiceCache implements CacheProvider {
|
|||
return this.cache.set(key, value, { preserveTTL: true });
|
||||
}
|
||||
|
||||
async setIfExists<T = any>(key: string, value: T, ttl?: number): Promise<boolean> {
|
||||
async setIfExists<T = unknown>(key: string, value: T, ttl?: number): Promise<boolean> {
|
||||
if (this.cache.setIfExists) {
|
||||
return this.cache.setIfExists(key, value, ttl);
|
||||
}
|
||||
|
|
@ -115,7 +116,7 @@ export class ServiceCache implements CacheProvider {
|
|||
return result !== null;
|
||||
}
|
||||
|
||||
async setIfNotExists<T = any>(key: string, value: T, ttl?: number): Promise<boolean> {
|
||||
async setIfNotExists<T = unknown>(key: string, value: T, ttl?: number): Promise<boolean> {
|
||||
if (this.cache.setIfNotExists) {
|
||||
return this.cache.setIfNotExists(key, value, ttl);
|
||||
}
|
||||
|
|
@ -124,7 +125,7 @@ export class ServiceCache implements CacheProvider {
|
|||
return result !== null;
|
||||
}
|
||||
|
||||
async replace<T = any>(key: string, value: T, ttl?: number): Promise<T | null> {
|
||||
async replace<T = unknown>(key: string, value: T, ttl?: number): Promise<T | null> {
|
||||
if (this.cache.replace) {
|
||||
return this.cache.replace(key, value, ttl);
|
||||
}
|
||||
|
|
@ -132,7 +133,7 @@ export class ServiceCache implements CacheProvider {
|
|||
return this.cache.set(key, value, ttl);
|
||||
}
|
||||
|
||||
async updateField<T = any>(
|
||||
async updateField<T = unknown>(
|
||||
key: string,
|
||||
updater: (current: T | null) => T,
|
||||
ttl?: number
|
||||
|
|
@ -172,7 +173,7 @@ export class ServiceCache implements CacheProvider {
|
|||
export function createServiceCache(
|
||||
serviceName: string,
|
||||
redisConfig: RedisConfig,
|
||||
options: { global?: boolean; logger?: any } = {}
|
||||
options: { global?: boolean; logger?: LoggerLike } = {}
|
||||
): ServiceCache {
|
||||
return new ServiceCache(serviceName, redisConfig, options.global, options.logger);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue