Skip to content

Commit

Permalink
add cache key scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Jan 9, 2024
1 parent 34defa9 commit a91a716
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libs/common/src/utils/cache.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ export class CacheInfo {

static Apps(): CacheInfo {
return {
key: 'apps',
key: this.toScopedKey('apps'),
ttl: Constants.oneMonth() * 12,
}
}

static AppDelegations(app: AppInfo): CacheInfo {
return {
key: `appDelegations:${app.id}`,
key: this.toScopedKey(`appDelegations:${app.id}`),
ttl: Constants.oneMonth() * 12,
}
}

static LastProcessedNonce(shardId: number): CacheInfo {
return {
key: `lastProcessedNonce:${shardId}`,
key: this.toScopedKey(`lastProcessedNonce:${shardId}`),
ttl: Constants.oneMonth(),
}
}

private static toScopedKey(name: string): string {
const appName = process.env.APP_NAME || 'multiversx'
const appEnv = process.env.APP_ENV || 'dev'

return `cache:${appName}:${appEnv}:${name}`
}
}

0 comments on commit a91a716

Please sign in to comment.