mirror of
https://github.com/direct-img/direct-img.link.git
synced 2026-03-17 03:01:01 +00:00
Refactor: Increase cache TTL to 60 days
This commit is contained in:
@@ -25,7 +25,7 @@ export async function onRequest(context) {
|
|||||||
const obj = await env.R2_IMAGES.get(r2Key);
|
const obj = await env.R2_IMAGES.get(r2Key);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
const nowSec = Math.floor(Date.now() / 1000);
|
const nowSec = Math.floor(Date.now() / 1000);
|
||||||
const remainingSec = Math.max(0, (cached.t + 2592000) - nowSec);
|
const remainingSec = Math.max(0, (cached.t + 5184000) - nowSec);
|
||||||
return new Response(obj.body, { headers: imageHeaders(cached.ct, remainingSec * 1000) });
|
return new Response(obj.body, { headers: imageHeaders(cached.ct, remainingSec * 1000) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ export async function onRequest(context) {
|
|||||||
const { buffer: imgBuffer, contentType: finalContentType } = imgResult;
|
const { buffer: imgBuffer, contentType: finalContentType } = imgResult;
|
||||||
await env.R2_IMAGES.put(r2Key, imgBuffer, { httpMetadata: { contentType: finalContentType } });
|
await env.R2_IMAGES.put(r2Key, imgBuffer, { httpMetadata: { contentType: finalContentType } });
|
||||||
|
|
||||||
const TTL_SECONDS = 2592000;
|
const TTL_SECONDS = 5184000;
|
||||||
await env.DIRECT_IMG_CACHE.put(cacheKey, JSON.stringify({ t: Math.floor(Date.now() / 1000), ct: finalContentType }), { expirationTtl: TTL_SECONDS });
|
await env.DIRECT_IMG_CACHE.put(cacheKey, JSON.stringify({ t: Math.floor(Date.now() / 1000), ct: finalContentType }), { expirationTtl: TTL_SECONDS });
|
||||||
|
|
||||||
return new Response(imgBuffer, { headers: imageHeaders(finalContentType, TTL_SECONDS * 1000) });
|
return new Response(imgBuffer, { headers: imageHeaders(finalContentType, TTL_SECONDS * 1000) });
|
||||||
|
|||||||
Reference in New Issue
Block a user