From a91a716b49e9f6467d0a086a4d7b34e22e5c9eda Mon Sep 17 00:00:00 2001 From: Micha Vie Date: Tue, 9 Jan 2024 21:35:57 +0100 Subject: [PATCH] add cache key scoping --- libs/common/src/utils/cache.info.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/common/src/utils/cache.info.ts b/libs/common/src/utils/cache.info.ts index 027c197..fb1fa4f 100644 --- a/libs/common/src/utils/cache.info.ts +++ b/libs/common/src/utils/cache.info.ts @@ -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}` + } }