Skip to content

Commit

Permalink
fix: use url as cache key which contains query params (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito authored Jul 25, 2024
1 parent 1d464a5 commit 68e22c5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions apps/api/src/app/plugins/bffCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const bffCache: FastifyPluginCallback<BffCacheOptions> = (fastify, opts,
return
}

let key = getKey(request)
const key = getKey(request);
// Remove it so we can cache it properly
request.headers['accept-encoding'] = undefined;

Expand Down Expand Up @@ -59,7 +59,6 @@ export const bffCache: FastifyPluginCallback<BffCacheOptions> = (fastify, opts,
contents += chunk.toString(); // Process each chunk of data
}


const key = getKey(req);
setCache(key, contents, cacheTtl, fastify).catch((e) => {
fastify.log.error(`Error setting key ${key} from cache`, e);
Expand All @@ -74,7 +73,7 @@ export const bffCache: FastifyPluginCallback<BffCacheOptions> = (fastify, opts,
};

function getKey(req: FastifyRequest) {
return `GET:${req.routerPath}`;
return `GET:${req.url}`;
}

function getTtlFromResponse(reply: FastifyReply, defaultTtl: number | undefined): number | undefined {
Expand Down

0 comments on commit 68e22c5

Please sign in to comment.