Skip to content

Commit

Permalink
Increase caching time (#71)
Browse files Browse the repository at this point in the history
* Increase caching time

* Add value

* Remove logs
  • Loading branch information
anxolin authored Jul 30, 2024
1 parent a945326 commit cce10ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 10 additions & 2 deletions apps/api/src/app/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +24,7 @@ import {
slippageServiceSymbol,
usdServiceSymbol,
} from '@cowprotocol/services';
import ms from 'ms';

function getTokenDecimals(tokenAddress: string): number | null {
return 18; // TODO: Implement!!!
Expand All @@ -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
);
}

Expand All @@ -48,7 +54,9 @@ function getUsdRepositoryCoingecko(
return new UsdRepositoryCache(
new UsdRepositoryCoingecko(),
cacheRepository,
'usdCoingecko'
'usdCoingecko',
DEFAULT_CACHE_VALUE_SECONDS,
DEFAULT_CACHE_NULL_SECONDS
);
}

Expand Down
7 changes: 2 additions & 5 deletions libs/repositories/src/UsdRepository/UsdRepositoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}`;
}
Expand Down

0 comments on commit cce10ef

Please sign in to comment.