Files
ipass-plugin-cache/www/cache.html
T
ssw 43718bd0c4 iPass cache gateway 源码
容量管理: zones.rs 直读 nginx file_cache 共享内存记账(双轴: 磁盘 + keys_zone 索引内存), ?scan=1 扫盘上限 20 万文件; POST /api/admin/cache/purge 整区清理(只删文件不删目录, 根治 [crit] mkdir failed); POST /api/admin/cache/invalidate 按制品精准失效(预览->确认两步式, glob/子串, 删除上限 5000/扫描上限 20 万); GET /api/admin/cache 新增 capacity 块; 前端容量面板 + 按制品失效工具条; 测试 test-cache-capacity.sh 48/48(容量 27 + 精准失效 21, 含 EXPECT_MIN 护栏与前端静态契约); docs 容量管理章节
2026-09-21 09:25:11 +08:00

124 lines
6.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<base href="/admin/">
<title>制品缓存 · 尚数网 山海关</title>
<link rel="stylesheet" href="assets/admin.css">
</head>
<body>
<div id="shell"></div>
<div class="wrap">
<!-- ================= 上游配置 ================= -->
<div class="panel">
<div class="panel-head">
<div>
<h2>制品缓存 · 上游</h2>
<div class="desc">
客户端把包管理器指向左侧的「下游地址」并携带账号 API Key,网关校验 Key 后按本表配置转发到上游、把响应落到本地磁盘缓存(命中不再回源)。
一个生态可能有<b>两个</b>上游:例如 crates.io 的索引在 <code>index.crates.io</code>、而 <code>.crate</code> 包本体在 <code>static.crates.io</code>,所以要分开配 <code>/cargo/</code> 与 <code>/cargo-dl/</code>。
「凭据」填<b>完整的 Authorization 头值</b>(如 <code>Bearer xxx</code>),留空则透传客户端自带的 Authorization;网关自己的 <code>sk_</code> 始终不会传给上游。
停用某个路由,对客户端表现为 <b>503 上游未配置</b>。
</div>
</div>
<button class="btn-sm" id="cRefresh">刷新</button>
</div>
<table>
<thead><tr>
<th>生态</th><th>路由 / 下游地址</th><th>上游地址</th><th>凭据</th><th>状态</th><th>操作</th>
</tr></thead>
<tbody id="cacheBody"></tbody>
</table>
<div class="desc" id="cacheEntry" style="margin-top:10px"></div>
</div>
<!-- ================= 容量与淘汰 ================= -->
<div class="panel">
<div class="panel-head">
<div>
<h2>容量与淘汰</h2>
<div class="desc">
数字<b>直接读自 nginx 自己的缓存记账</b>(<code>proxy_cache_path</code> 的共享内存),口径与淘汰动作同源 —— 「这里显示 91%」与「nginx 正在淘汰」说的是同一件事,不是扫盘估算。
上限来自 conf 的 <code>max_size</code>(默认每生态 50g、docker 200g),超了按 <b>LRU</b> 自动淘汰;<code>inactive</code> 到期的条目也会被清掉。淘汰是<b>渐进</b>的(cache manager 每秒一轮),短时猛灌可短暂超过上限再收敛,它不是硬配额。
<br>「盘点磁盘」会把真实占用也列出来:两者差额是 <b>nginx 还没回收的条目</b>(手工清过缓存文件后会明显偏大,节点要等再被访问或到期才释放)—— 差多少就照实显示,不替你对平。
<br>另一条容易漏掉的轴是<b>索引内存</b>(<code>keys_zone</code>:条目元数据住这里,不占磁盘)。它吃紧时 nginx 会改按<b>条目数</b>强制回收,看板上的「索引吃紧」标记就是它 —— 该扩 <code>keys_zone</code> 了。
<br>「清空」只删缓存文件、<b>保留目录</b>:手工 <code>rm</code> 掉 <code>cache/&lt;生态&gt;</code> 目录会让该路由此后每次写缓存都失败并断开客户端(直到 restart),这个坑踩过,所以清理必须由网关来做。
</div>
</div>
<div class="row-actions">
<button class="btn-sm" id="capRefresh">刷新读数</button>
<button class="btn-sm" id="capScan">盘点磁盘</button>
<button class="btn-sm btn-danger" id="capPurgeAll">清空全部</button>
</div>
</div>
<div class="desc" id="capSummary"></div>
<table>
<thead><tr>
<th>缓存区</th><th>磁盘目录</th><th style="min-width:230px">占用 / 上限</th>
<th>条目数</th><th>索引内存</th><th>状态</th><th>操作</th>
</tr></thead>
<tbody id="capBody"></tbody>
</table>
<!-- 按制品失效:粒度比「清空整区」细一档。
上游把某个版本发坏了、某个 metadata 发布错了时,真正要扔的只有几个文件,
清掉整个生态等于几十 GB 白重拉。两步式(预览 → 确认)是刻意的:
支持通配就意味着「写宽了 = 事故」,所以先给一次无副作用的预览。 -->
<div class="inval-bar">
<b>按制品失效</b>
<input type="text" id="capMatch"
placeholder="制品关键字:lodash、library/alpine,支持 * 通配(如 npm:/npm/*)">
<select id="capZone"><option value="all">全部缓存区</option></select>
<button class="btn-sm" id="capPreview">预览命中</button>
<button class="btn-sm btn-danger" id="capApply" disabled>确认失效</button>
</div>
<div class="desc" id="capInvalResult" style="margin-top:8px"></div>
<div class="inval-keys" id="capInvalKeys" style="display:none"></div>
</div>
<!-- ================= 命中计数 ================= -->
<div class="panel">
<div class="panel-head">
<div>
<h2>命中计数</h2>
<div class="desc">
来自网关共享内存的运行期读数(按生态 × <code>$upstream_cache_status</code>,含跨生态汇总行 <code>global</code>)。
只统计真的进了缓存层的请求;被鉴权拦下或上游连不上的请求不计入分母。<b>网关重启读数归零</b>,但磁盘上的缓存文件仍在(命中不会因此变回 MISS)。
</div>
</div>
</div>
<table>
<thead><tr>
<th>生态</th><th>HIT</th><th>MISS</th><th>BYPASS</th><th>EXPIRED</th><th>REVALIDATED</th><th>UPDATING</th><th>STALE</th><th>命中率</th>
</tr></thead>
<tbody id="statsBody"></tbody>
</table>
</div>
<!-- ================= 变量契约(排障用) ================= -->
<div class="panel">
<div class="panel-head">
<div>
<h2>nginx 变量契约</h2>
<div class="desc">
下面这几个变量由网关模块按「上游表 + 请求 URI」实时算出,nginx 配置里直接引用即可。
改上游地址/凭据<b>不需要改 conf、也不需要 reload</b> —— 变量每次求值都读共享内存。
</div>
</div>
</div>
<table>
<thead><tr><th>变量</th><th>含义</th></tr></thead>
<tbody id="varBody"></tbody>
</table>
</div>
</div>
<div id="toast"></div>
<script src="assets/core.js"></script>
<script src="assets/cache.js"></script>
</body>
</html>