lmcache kvcache#
lmcache kvcache 命令管理正在运行的 LMCache 服务器上的 KV Cache 状态。
lmcache kvcache <sub-command> [options]
$ lmcache kvcache -h
usage: lmcache kvcache [-h] [--format FORMAT] [--output PATH] [-q] {clear} ...
Manage KV cache state.
subcommands:
clear Clear all cached KV data in L1 (CPU)
options:
-h, --help show this help message and exit
--format FORMAT Stdout output format (default: terminal). Available: terminal, json.
--output PATH Save metrics to a file at PATH (format chosen by --format).
-q, --quiet Suppress stdout output. Exit code only.
清除#
清除目标 LMCache 服务器上 L1 (CPU 内存) 中所有缓存的 KV 数据。
lmcache kvcache clear --url <MP_HTTP_URL>
示例:
$ lmcache kvcache clear --url http://localhost:8000
================ KV Cache Clear ================
Status: OK
================================================
JSON 输出 (用于与 jq 脚本交互):
$ lmcache kvcache clear --url http://localhost:8000 --format json
{
"title": "KV Cache Clear",
"metrics": {
"status": "OK"
}
}
**静默模式**(仅退出代码,无输出):
$ lmcache kvcache clear -q --url http://localhost:8000
$ echo $?
0
选项#
标志 |
必需的 |
描述 |
|---|---|---|
|
是的 |
LMCache MP HTTP 服务器的 URL(例如 |
|
否 |
输出格式: |
|
否 |
将输出保存到文件中(使用 |
|
否 |
抑制标准输出。在只需要退出代码的脚本中很有用。 |
退出代码#
代码 |
含义 |
|---|---|
|
成功。 |
|
错误(连接失败、服务器错误、参数错误)。 |
常见模式#
处理临时服务器不可用:
如果服务器暂时无法访问(例如,由于网络问题),命令将以退出代码 1 失败。对于持续的连接问题,请使用 lmcache ping 进行诊断。
if lmcache kvcache clear -q --url http://localhost:8000; then
echo "Cache cleared"
else
echo "Clear failed — server temporarily unreachable, retrying later"
fi
清除缓存并捕获 JSON 结果:
RESULT=$(lmcache kvcache clear --url http://localhost:8000 --format json)
STATUS=$(echo "$RESULT" | jq -r '.metrics.status')
echo "Clear status: $STATUS"