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

Commit

Permalink
feat(votium): Add TTL on Votium keys to allow prior claimable amounts…
Browse files Browse the repository at this point in the history
… to expire (#999)
  • Loading branch information
immasandwich authored Aug 2, 2022
1 parent 0f1fb74 commit 9748e9c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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

0 comments on commit 9748e9c

Please sign in to comment.