Chore: print statusCode when cache miss

This commit is contained in:
SukkaW
2024-10-09 20:58:06 +08:00
parent d4f84e97f9
commit 3e7ef5a294

View File

@@ -225,12 +225,11 @@ export class Cache<S = string> {
const etag = this.get(etagKey);
const onMiss = (resp: Response) => {
const onMiss = async (resp: Response) => {
const serializer = 'serializer' in opt ? opt.serializer : identity as any;
const promise = fn(resp);
const value = await fn(resp);
return promise.then((value) => {
if (resp.headers.has('ETag')) {
let serverETag = resp.headers.get('ETag')!;
// FUCK someonewhocares.org
@@ -238,7 +237,7 @@ export class Cache<S = string> {
serverETag = serverETag.replace('-gzip', '');
}
console.log(picocolors.yellow('[cache] miss'), url, { cachedETag: etag, serverETag });
console.log(picocolors.yellow('[cache] miss'), url, { status: resp.status, cachedETag: etag, serverETag });
this.set(etagKey, serverETag, TTL.ONE_WEEK_STATIC);
this.set(cachedKey, serializer(value), TTL.ONE_WEEK_STATIC);
@@ -252,7 +251,6 @@ export class Cache<S = string> {
}
return value;
});
};
const cached = this.get(cachedKey);