diff --git a/src/app-toolkit/app-toolkit.interface.ts b/src/app-toolkit/app-toolkit.interface.ts index 974aa8b6c..627191d7a 100644 --- a/src/app-toolkit/app-toolkit.interface.ts +++ b/src/app-toolkit/app-toolkit.interface.ts @@ -58,7 +58,7 @@ export interface IAppToolkit { // Cache getFromCache(key: string): Promise; - msetToCache(entries: [string, T][]): Promise; + setManyToCache(entries: [string, T][], ttl?: number): Promise; // Global Helpers diff --git a/src/app-toolkit/app-toolkit.service.ts b/src/app-toolkit/app-toolkit.service.ts index 704127d44..12efc6afb 100644 --- a/src/app-toolkit/app-toolkit.service.ts +++ b/src/app-toolkit/app-toolkit.service.ts @@ -102,9 +102,9 @@ export class AppToolkit implements IAppToolkit { return this.cacheManager.get(key); } - async msetToCache(entries: [string, T][]) { - // In production, this is a Redis `mset` - await Promise.all(entries.map(([key, value]) => this.cacheManager.set(key, value))); + async setManyToCache(entries: [string, T][], ttl = 60) { + // In production, this is a Redis pipeline of `set` commands + await Promise.all(entries.map(([key, value]) => this.cacheManager.set(key, value, { ttl }))); } // Global Helpers diff --git a/src/app-toolkit/helpers/merkle/merkle.cache.ts b/src/app-toolkit/helpers/merkle/merkle.cache.ts index 57f0bbcd1..4b4d51110 100644 --- a/src/app-toolkit/helpers/merkle/merkle.cache.ts +++ b/src/app-toolkit/helpers/merkle/merkle.cache.ts @@ -1,5 +1,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { entries } from 'lodash'; +import moment from 'moment'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { Schedule } from '~scheduler/scheduler.decorator'; @@ -29,7 +30,7 @@ export abstract class MerkleCache { } @Schedule({ - every: 15 * 60 * 1000, + every: moment.duration('5', 'minutes').asMilliseconds(), }) async cacheMerkleData() { const data = await this.resolveMerkleData(); @@ -40,7 +41,7 @@ export abstract class MerkleCache { }); }); - await this.appToolkit.msetToCache(cacheable); + await this.appToolkit.setManyToCache(cacheable, moment.duration('30', 'minutes').asSeconds()); } async getClaim(rewardTokenAddress: string, walletAddress: string) {