Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-laws-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@wbce-d9/api': major
---

optimization on cache middleware
7 changes: 2 additions & 5 deletions api/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Keyv from 'keyv';
import env from './env.js';
import logger from './logger.js';
import { getMessenger } from './messenger.js';
import { compress, decompress } from './utils/compress.js';
import { getConfigFromEnv } from './utils/get-config-from-env.js';
import { getMilliseconds } from './utils/get-milliseconds.js';
import { validateEnv } from './utils/validate-env.js';
Expand Down Expand Up @@ -141,15 +140,13 @@ export async function setCacheValue(
value: Record<string, any> | Record<string, any>[],
ttl?: number
) {
const compressed = await compress(value);
await cache.set(key, compressed, ttl);
await cache.set(key, value, ttl);
}

export async function getCacheValue(cache: Keyv, key: string): Promise<any> {
const value = await cache.get(key);
if (!value) return undefined;
const decompressed = await decompress(value);
return decompressed;
return value;
}

function getKeyvInstance(store: Store, ttl: number | undefined, namespaceSuffix?: string): Keyv {
Expand Down