feat(cache): read cache TTLs from storage settings and renew tracked TMDB details (CACHE-2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-29 17:16:50 +08:00
1 parent 58e358e4a9
commit 85b352b8eb
10 files changed
+140 -35

No files matched your search

+3 -4
View File
@@ -17,10 +17,11 @@ import {
type WebSearchTestResult,
} from "@umt/contracts";
import { cachedCall, pgCacheFor, pgTokenBucketFor } from "@umt/db";
import { storageSettings } from "../../shared-cache.ts";
import type { ServerContext } from "../types.ts";
/**
* WEB-1 网页搜索服务:Brave 客户端之上的 Key 读取、每分钟上限(跨进程令牌桶)、10 分钟 PG 缓存(kv_cache region websearch)、
* WEB-1 网页搜索服务:Brave 客户端之上的 Key 读取、每分钟上限(跨进程令牌桶)、PG 缓存(kv_cache region websearch,TTL = storage.cacheTtl.webSearchDays)、
* 以及 web.fetch 的白名单——按调用方(Agent 会话 / 其它调用者)记录最近一次 web.search 返回的 URL,只允许读取这些 URL。
*/
@@ -36,8 +37,6 @@ export interface WebSearchModuleOptions {
export const WEBSEARCH_CACHE_REGION = "websearch";
/** 白名单:key = 调用方,value = 最近一次搜索的 URL */
export const WEBSEARCH_ALLOW_REGION = "websearch.allow";
/** 搜索结果缓存 10 分钟 */
export const SEARCH_CACHE_TTL_SEC = 600;
const SEARCH_CACHE_MAX = 1000;
/** 白名单保留 6 小时(会话时长上限远小于此) */
const ALLOW_TTL_SEC = 6 * 3600;
@@ -142,7 +141,7 @@ export class WebSearchService {
key,
{
region: WEBSEARCH_CACHE_REGION,
ttl: SEARCH_CACHE_TTL_SEC,
ttl: (await storageSettings(this.ctx)).cacheTtl.webSearchDays * 86_400,
maxsize: SEARCH_CACHE_MAX,
...(o.fresh ? { fresh: true } : {}),
},