Skip to content

Commit bd22304

Browse files
committed
refactor: change getOrSetCache to use positional params
1 parent 7b9b1c1 commit bd22304

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

src/cache/custom-cache.service.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class CustomCacheService {
4444
const methodOverride = async (...args: unknown[]) => {
4545
const result = async () => await methodRef.apply(instance, args);
4646

47-
return this.getOrSetCache({ customKey, options, result, args });
47+
return this.getOrSetCache(customKey, args, options, result);
4848
};
4949

5050
Object.defineProperty(instance, methodName, {
@@ -75,17 +75,12 @@ export class CustomCacheService {
7575
return customKey + JSON.stringify(args);
7676
}
7777

78-
async getOrSetCache({
79-
options,
80-
args,
81-
result: _result,
82-
customKey,
83-
}: {
84-
options: CustomCacheOptions;
85-
args: unknown[];
86-
result: () => Promise<unknown>;
87-
customKey: string;
88-
}) {
78+
async getOrSetCache(
79+
customKey: string,
80+
args: unknown[],
81+
options: CustomCacheOptions,
82+
resultFn: () => Promise<unknown>,
83+
) {
8984
const { key: cacheKey = customKey, ttl = Infinity, logger } = options;
9085
const argsAddedKey = this.buildCacheKey(cacheKey, args);
9186

@@ -94,7 +89,7 @@ export class CustomCacheService {
9489
return cachedValue;
9590
}
9691

97-
const result = await _result();
92+
const result = await resultFn();
9893
await this.setCache(argsAddedKey, result, ttl, logger);
9994

10095
return result;

0 commit comments

Comments
 (0)