Skip to content

Commit 11110ea

Browse files
authored
Merge pull request #138 from cloudflare/mendess/fix-public-key-caching
Fix public key caching causing key spill over between prefixes
2 parents 10eec63 + 90d94f8 commit 11110ea

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/cache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ export class InMemoryCryptoKeyCache {
122122
key: string,
123123
setValFn: (key: string) => Promise<CacheElement<CryptoKey>>
124124
): Promise<CryptoKey> {
125+
const prefixedKey = `${this.ctx.prefix ?? ''}/${key}`;
126+
125127
const refreshCache = async () => {
126128
const val = await setValFn(key);
127-
InMemoryCryptoKeyCache.store.set(key, val);
129+
InMemoryCryptoKeyCache.store.set(prefixedKey, val);
128130
return val.value;
129131
};
130132

131-
const cachedValue = InMemoryCryptoKeyCache.store.get(key);
133+
const cachedValue = InMemoryCryptoKeyCache.store.get(prefixedKey);
132134
if (cachedValue) {
133135
this.ctx.waitUntil(
134136
(() => {

0 commit comments

Comments
 (0)