Skip to content

Commit 5726a10

Browse files
committed
feat: pass in current phase (read or write) to multicache get key method
1 parent 258f01a commit 5726a10

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ts-cache/src/decorator/multicache.decorator.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const defaultKeyStrategy = {
55
className: string,
66
methodName: string,
77
parameter: any,
8-
args: any
8+
args: any,
9+
_phase: 'read' | 'write'
910
): string {
1011
return `${className}:${methodName}:${JSON.stringify(
1112
parameter
@@ -53,7 +54,7 @@ export function MultiCache(
5354
const parameters = args[parameterIndex];
5455
const cacheKeys: (string | undefined)[] = parameters.map(
5556
(parameter: any) => {
56-
return keyStrategy.getKey(className, methodName, parameter, args);
57+
return keyStrategy.getKey(className, methodName, parameter, args, 'read');
5758
}
5859
);
5960

@@ -68,7 +69,7 @@ export function MultiCache(
6869

6970
// console.log('foundEntries', foundEntries);
7071

71-
// remove all foudn entries from cacheKeys
72+
// remove all found entries from cacheKeys
7273
Object.keys(foundEntries).forEach((entry) => {
7374
if (foundEntries[entry] === undefined) return;
7475
// remove entry from cacheKey
@@ -140,7 +141,8 @@ export function MultiCache(
140141
className,
141142
methodName,
142143
missingKeys[i],
143-
args
144+
args,
145+
'write'
144146
),
145147
content,
146148
};

ts-cache/test/multicache.decorator.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class TestClassOne {
2323
_className: string,
2424
_methodName: string,
2525
parameter: any,
26-
args: any
26+
args: any,
27+
_phase: 'read' | 'write'
2728
): string {
2829
// args[1] = geoRegion
2930
return `{canonicalurl:${args[1].toUpperCase()}}:${parameter.pageType}:${

0 commit comments

Comments
 (0)