Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

feat(votium): Add TTL on Votium keys to allow prior claimable amounts to expire #999

Merged
merged 3 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app-toolkit/app-toolkit.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface IAppToolkit {
// Cache

getFromCache<T = any>(key: string): Promise<T | undefined>;
msetToCache<T = any>(entries: [string, T][]): Promise<void>;
setManyToCache<T = any>(entries: [string, T][], ttl?: number): Promise<void>;

// Global Helpers

Expand Down
6 changes: 3 additions & 3 deletions src/app-toolkit/app-toolkit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export class AppToolkit implements IAppToolkit {
return this.cacheManager.get<T>(key);
}

async msetToCache<T = any>(entries: [string, T][]) {
// In production, this is a Redis `mset`
await Promise.all(entries.map(([key, value]) => this.cacheManager.set(key, value)));
async setManyToCache<T = any>(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
Expand Down
5 changes: 3 additions & 2 deletions src/app-toolkit/helpers/merkle/merkle.cache.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -29,7 +30,7 @@ export abstract class MerkleCache<T = any> {
}

@Schedule({
every: 15 * 60 * 1000,
every: moment.duration('5', 'minutes').asMilliseconds(),
})
async cacheMerkleData() {
const data = await this.resolveMerkleData();
Expand All @@ -40,7 +41,7 @@ export abstract class MerkleCache<T = any> {
});
});

await this.appToolkit.msetToCache(cacheable);
await this.appToolkit.setManyToCache(cacheable, moment.duration('30', 'minutes').asSeconds());
}

async getClaim(rewardTokenAddress: string, walletAddress: string) {
Expand Down