From 71e87385453fd04e43b768aa19372233dc548499 Mon Sep 17 00:00:00 2001 From: Hansol Lim Date: Sun, 27 Sep 2026 04:28:20 +0900 Subject: [PATCH] =?UTF-8?q?fix(content):=20OneDrive=20=ED=85=8D=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BA=90=EC=8B=9C=EA=B0=80=20=EB=91=90=20=EA=B2=B9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=8C=93=EC=97=AC=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=EC=9D=B4=20=EB=8A=A6=EC=96=B4=EC=A7=80=EB=8D=98=20=EA=B2=83?= =?UTF-8?q?=EC=9D=84=20=ED=95=9C=20=EA=B2=B9=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 데이터 캐시 재검증 때 인스턴스 메모리 캐시를 건너뛰고, 캐시 키를 바꿔 기존 항목을 버린다. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013AJufoD68ZCmdcq1fhN2az --- src/lib/content/onedrive-text.ts | 4 ++-- src/lib/onedrive/graph.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/content/onedrive-text.ts b/src/lib/content/onedrive-text.ts index 295bc97..9c77844 100644 --- a/src/lib/content/onedrive-text.ts +++ b/src/lib/content/onedrive-text.ts @@ -4,11 +4,11 @@ import { isOneDriveConfigured, readText } from "@/lib/onedrive/graph"; /** * 사이트가 읽는 OneDrive 텍스트(site-data, 원페이저, Ask Hansol 문맥)를 Next 데이터 캐시에 얹는다. * Graph 조회는 콜드 스타트에 1~3초 걸려서, 인스턴스 사이에서 공유되는 캐시(5분 재검증, stale-while-revalidate) - * 가 페이지 응답 시간을 지킨다. 파일을 고치면 늦어도 약 5분 뒤 반영된다. + * 가 페이지 응답 시간을 지킨다. 파일을 고치면 보통 5분 안팎, 늦어도 10분 안에 반영된다(재검증은 요청이 올 때 뒤에서 돈다). */ const REVALIDATE_SECONDS = Number(process.env.ONEDRIVE_TEXT_REVALIDATE_SECONDS ?? 300); -const cachedRead = unstable_cache(async (relPath: string) => readText(relPath), ["onedrive-text-v1"], { +const cachedRead = unstable_cache(async (relPath: string) => readText(relPath, { fresh: true }), ["onedrive-text-v2"], { revalidate: REVALIDATE_SECONDS, tags: ["onedrive-text"], }); diff --git a/src/lib/onedrive/graph.ts b/src/lib/onedrive/graph.ts index fd125a4..29f45ab 100644 --- a/src/lib/onedrive/graph.ts +++ b/src/lib/onedrive/graph.ts @@ -193,10 +193,13 @@ export async function readBytes(relPath: string): Promise { return res.arrayBuffer(); } -/** 텍스트 파일 읽기. 인스턴스 메모리에 5분 캐시(오류는 캐시하지 않는다). 없으면 null. */ -export async function readText(relPath: string): Promise { +/** + * 텍스트 파일 읽기. 없으면 null. 기본은 인스턴스 메모리에 5분 캐시(오류는 캐시하지 않는다). + * `fresh: true` 면 메모리 캐시를 건너뛴다(바깥에 다른 캐시가 있을 때 두 캐시가 겹쳐 반영이 늦어지지 않게). + */ +export async function readText(relPath: string, opts: { fresh?: boolean } = {}): Promise { const now = Date.now(); - const hit = textCache.get(relPath); + const hit = opts.fresh ? undefined : textCache.get(relPath); if (hit && hit.expiresAt > now) return hit.text; const buf = await readBytes(relPath); const text = buf ? new TextDecoder("utf-8").decode(buf) : null;