diff --git a/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.spec.ts b/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.spec.ts index 4d304376a45..79e0819fc1c 100644 --- a/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.spec.ts +++ b/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.spec.ts @@ -83,7 +83,7 @@ describe("PlatformCacheInterceptor", () => { set: jest.fn().mockResolvedValue(false), del: jest.fn().mockResolvedValue(true), ttl: jest.fn().mockResolvedValue(6999), - calculateTTL: jest.fn().mockReturnValue(10000) + calculateTTL: jest.fn().mockImplementation((result: any, ttl: any) => ttl) }; const interceptor = await PlatformTest.invoke(PlatformCacheInterceptor, [ { @@ -108,7 +108,7 @@ describe("PlatformCacheInterceptor", () => { set: jest.fn().mockResolvedValue(false), del: jest.fn().mockResolvedValue(true), ttl: jest.fn().mockResolvedValue(9700), - calculateTTL: jest.fn().mockReturnValue(10000) + calculateTTL: jest.fn().mockImplementation((result: any, ttl: any) => ttl) }; const interceptor = await PlatformTest.invoke(PlatformCacheInterceptor, [ { @@ -134,7 +134,7 @@ describe("PlatformCacheInterceptor", () => { get: jest.fn().mockResolvedValue(false), set: jest.fn().mockResolvedValue(false), del: jest.fn().mockResolvedValue(true), - calculateTTL: jest.fn().mockReturnValue(10000), + calculateTTL: jest.fn().mockImplementation((result: any, ttl: any) => ttl), getCachedObject: jest.fn().mockResolvedValue({ data: JSON.stringify({data: "data"}) }), @@ -185,7 +185,7 @@ describe("PlatformCacheInterceptor", () => { get: jest.fn().mockResolvedValue(false), set: jest.fn().mockResolvedValue(false), del: jest.fn().mockResolvedValue(true), - calculateTTL: jest.fn().mockReturnValue(10000), + calculateTTL: jest.fn().mockImplementation((result: any, ttl: any) => ttl), getCachedObject: jest.fn().mockResolvedValue(undefined), setCachedObject: jest.fn().mockResolvedValue("test"), defaultKeyResolver: () => defaultKeyResolver diff --git a/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.ts b/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.ts index 81b52fa799d..0ee6039dd92 100644 --- a/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.ts +++ b/packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.ts @@ -45,7 +45,7 @@ export class PlatformCacheInterceptor implements InterceptorMethods { await this.addKeyToQueue(key); const currentTTL = await this.cache.ttl(key); - const calculatedTTL = this.cache.calculateTTL(ttl); + const calculatedTTL = this.cache.calculateTTL(currentTTL, ttl); if (currentTTL < calculatedTTL - refreshThreshold) { await next();