diff --git a/apps/api/src/app/inversify.config.ts b/apps/api/src/app/inversify.config.ts index 4728ff2..00e9908 100644 --- a/apps/api/src/app/inversify.config.ts +++ b/apps/api/src/app/inversify.config.ts @@ -12,6 +12,9 @@ import { usdRepositorySymbol, } from '@cowprotocol/repositories'; +const DEFAULT_CACHE_VALUE_SECONDS = ms('2min') / 1000; // 2min cache time by default for values +const DEFAULT_CACHE_NULL_SECONDS = ms('30min') / 1000; // 30min cache time by default for NULL values (when the repository don't know) + import { Container } from 'inversify'; import { SlippageService, @@ -21,6 +24,7 @@ import { slippageServiceSymbol, usdServiceSymbol, } from '@cowprotocol/services'; +import ms from 'ms'; function getTokenDecimals(tokenAddress: string): number | null { return 18; // TODO: Implement!!! @@ -38,7 +42,9 @@ function getUsdRepositoryCow(cacheRepository: CacheRepository): UsdRepository { return new UsdRepositoryCache( new UsdRepositoryCow(getTokenDecimals), cacheRepository, - 'usdCow' + 'usdCow', + DEFAULT_CACHE_VALUE_SECONDS, + DEFAULT_CACHE_NULL_SECONDS ); } @@ -48,7 +54,9 @@ function getUsdRepositoryCoingecko( return new UsdRepositoryCache( new UsdRepositoryCoingecko(), cacheRepository, - 'usdCoingecko' + 'usdCoingecko', + DEFAULT_CACHE_VALUE_SECONDS, + DEFAULT_CACHE_NULL_SECONDS ); } diff --git a/libs/repositories/src/UsdRepository/UsdRepositoryCache.ts b/libs/repositories/src/UsdRepository/UsdRepositoryCache.ts index 546be56..b20ca22 100644 --- a/libs/repositories/src/UsdRepository/UsdRepositoryCache.ts +++ b/libs/repositories/src/UsdRepository/UsdRepositoryCache.ts @@ -8,12 +8,9 @@ import { usdRepositorySymbol, } from './UsdRepository'; import { SupportedChainId } from '../types'; -import IORedis from 'ioredis'; import ms from 'ms'; import { CacheRepository } from '../CacheRepository/CacheRepository'; -const DEFAULT_CACHE_VALUE_SECONDS = ms('10s') / 1000; // 2min cache time by default for values -const DEFAULT_CACHE_NULL_SECONDS = ms('30min') / 1000; // 2min cache time by default for NULL values (when the repository don't know) const NULL_VALUE = 'null'; @injectable() @@ -24,8 +21,8 @@ export class UsdRepositoryCache implements UsdRepository { private proxy: UsdRepository, @inject(usdRepositorySymbol) private cache: CacheRepository, private cacheName: string, - private cacheTimeValueSeconds: number = DEFAULT_CACHE_VALUE_SECONDS, - private cacheTimeNullSeconds: number = DEFAULT_CACHE_NULL_SECONDS + private cacheTimeValueSeconds: number, + private cacheTimeNullSeconds: number ) { this.baseCacheKey = `repos:${this.cacheName}`; }