Skip to content

Commit

Permalink
log size of resposnes being cached
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Aug 10, 2024
1 parent 556f6b5 commit 66502fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion plugins/plugin-use-cache-machine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function specialCache(request) {
export default function useCacheMachine(env) {
return {
async onParams({params, request, setParams, setResult, fetchAPI}) {
console.log(request.requestId);
if (env.SKIP_CACHE === 'true') {
console.log(`Skipping cache check due to SKIP_CACHE`);
return;
Expand All @@ -29,6 +30,9 @@ export default function useCacheMachine(env) {
},
onContextBuilding({context, extendContext, breakContextBuilding}) {
context.request.ctx = context.ctx ?? context.request.ctx;
if (typeof context.waitUntil === 'function') {
context.request.ctx.waitUntil = context.waitUntil;
}
context.request.data = context.data;
context.request.warnings = context.warnings;
context.request.errors = context.errors;
Expand Down Expand Up @@ -73,7 +77,6 @@ export default function useCacheMachine(env) {
// using waitUntil doesn't hold up returning a response but keeps the worker alive as long as needed
request.ctx.waitUntil(cacheMachine.put(env, request.params.query, request.params.variables, JSON.stringify(result), String(ttl), sCache));
}
console.log(request.requestId);
console.log(`kvs used in request: ${request.data.requests[request.requestId]?.kvUsed.join(', ') ?? 'none'}`);
request.data.clearRequestData(request.requestId);
delete request.requestId;
Expand Down
2 changes: 1 addition & 1 deletion utils/cache-machine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ async function updateCache(env, query, variables, body, ttl = '', specialCache =
}
// Get the cacheKey from the request
query = query.trim();
console.log(`caching response for ${env.ENVIRONMENT} environment${ttl ? ` for ${ttl} seconds` : ''}`);
const cacheKey = await hash(env.ENVIRONMENT + query + JSON.stringify(variables) + specialCache);
console.log(`Caching ${body.length} byte response for ${env.ENVIRONMENT} environment${ttl ? ` for ${ttl} seconds` : ''}`);

// headers and POST body
const headersPost = {
Expand Down

0 comments on commit 66502fe

Please sign in to comment.