缓存框架

This commit is contained in:
ryan
2026-06-11 15:10:11 +08:00
parent e8e0326879
commit 0221d4de14
20 changed files with 1699 additions and 11 deletions
+204
View File
@@ -455,6 +455,167 @@ const docTemplate = `{
}
}
},
"/api/v1/admin/cache/clear": {
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "清除系统磁盘缓存目录中的所有临时文件,并重置缓存容量和 Key 追踪数据",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "清空缓存",
"responses": {
"200": {
"description": "清理成功",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "服务内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/cache/config": {
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "更改磁盘缓存最大容量限制、文件生存时间(TTL)以及是否启用 LRU 淘汰淘汰算法,并进行热更新",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "更新缓存配置",
"parameters": [
{
"description": "缓存配置请求体",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/cache.updateCacheConfigRequest"
}
}
],
"responses": {
"200": {
"description": "更新成功",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "服务内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/cache/status": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "获取当前系统磁盘缓存的使用情况(已占用字节、Key 数量等)与策略配置",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "获取缓存状态",
"responses": {
"200": {
"description": "获取成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/diskcache.Status"
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/db-export": {
"get": {
"security": [
@@ -4350,6 +4511,26 @@ const docTemplate = `{
}
}
},
"cache.updateCacheConfigRequest": {
"type": "object",
"required": [
"max_size_mb",
"ttl_minutes"
],
"properties": {
"lru_enabled": {
"type": "boolean"
},
"max_size_mb": {
"type": "integer",
"minimum": 1
},
"ttl_minutes": {
"type": "integer",
"minimum": 0
}
}
},
"cap.ChallengeResponse": {
"type": "object",
"properties": {
@@ -4484,6 +4665,29 @@ const docTemplate = `{
}
}
},
"diskcache.Status": {
"type": "object",
"properties": {
"base_path": {
"type": "string"
},
"keys_count": {
"type": "integer"
},
"lru_enabled": {
"type": "boolean"
},
"max_size_mb": {
"type": "integer"
},
"total_size": {
"type": "integer"
},
"ttl_minutes": {
"type": "integer"
}
}
},
"logger.LogEntry": {
"type": "object",
"properties": {
+204
View File
@@ -448,6 +448,167 @@
}
}
},
"/api/v1/admin/cache/clear": {
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "清除系统磁盘缓存目录中的所有临时文件,并重置缓存容量和 Key 追踪数据",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "清空缓存",
"responses": {
"200": {
"description": "清理成功",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "服务内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/cache/config": {
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "更改磁盘缓存最大容量限制、文件生存时间(TTL)以及是否启用 LRU 淘汰淘汰算法,并进行热更新",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "更新缓存配置",
"parameters": [
{
"description": "缓存配置请求体",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/cache.updateCacheConfigRequest"
}
}
],
"responses": {
"200": {
"description": "更新成功",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "服务内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/cache/status": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "获取当前系统磁盘缓存的使用情况(已占用字节、Key 数量等)与策略配置",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "获取缓存状态",
"responses": {
"200": {
"description": "获取成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/diskcache.Status"
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/db-export": {
"get": {
"security": [
@@ -4343,6 +4504,26 @@
}
}
},
"cache.updateCacheConfigRequest": {
"type": "object",
"required": [
"max_size_mb",
"ttl_minutes"
],
"properties": {
"lru_enabled": {
"type": "boolean"
},
"max_size_mb": {
"type": "integer",
"minimum": 1
},
"ttl_minutes": {
"type": "integer",
"minimum": 0
}
}
},
"cap.ChallengeResponse": {
"type": "object",
"properties": {
@@ -4477,6 +4658,29 @@
}
}
},
"diskcache.Status": {
"type": "object",
"properties": {
"base_path": {
"type": "string"
},
"keys_count": {
"type": "integer"
},
"lru_enabled": {
"type": "boolean"
},
"max_size_mb": {
"type": "integer"
},
"total_size": {
"type": "integer"
},
"ttl_minutes": {
"type": "integer"
}
}
},
"logger.LogEntry": {
"type": "object",
"properties": {
+128
View File
@@ -26,6 +26,20 @@ definitions:
is_active:
type: boolean
type: object
cache.updateCacheConfigRequest:
properties:
lru_enabled:
type: boolean
max_size_mb:
minimum: 1
type: integer
ttl_minutes:
minimum: 0
type: integer
required:
- max_size_mb
- ttl_minutes
type: object
cap.ChallengeResponse:
properties:
challenge:
@@ -114,6 +128,21 @@ definitions:
description: '"select" 或 "exec"'
type: string
type: object
diskcache.Status:
properties:
base_path:
type: string
keys_count:
type: integer
lru_enabled:
type: boolean
max_size_mb:
type: integer
total_size:
type: integer
ttl_minutes:
type: integer
type: object
logger.LogEntry:
properties:
data:
@@ -1277,6 +1306,105 @@ paths:
summary: 切换认证源启用状态
tags:
- admin
/api/v1/admin/cache/clear:
post:
description: 清除系统磁盘缓存目录中的所有临时文件,并重置缓存容量和 Key 追踪数据
produces:
- application/json
responses:
"200":
description: 清理成功
schema:
$ref: '#/definitions/util.ResponseAny'
"401":
description: 未登录
schema:
$ref: '#/definitions/util.ResponseAny'
"403":
description: 无管理员权限
schema:
$ref: '#/definitions/util.ResponseAny'
"500":
description: 服务内部错误
schema:
$ref: '#/definitions/util.ResponseAny'
security:
- SessionCookie: []
summary: 清空缓存
tags:
- admin
/api/v1/admin/cache/config:
post:
consumes:
- application/json
description: 更改磁盘缓存最大容量限制、文件生存时间(TTL)以及是否启用 LRU 淘汰淘汰算法,并进行热更新
parameters:
- description: 缓存配置请求体
in: body
name: request
required: true
schema:
$ref: '#/definitions/cache.updateCacheConfigRequest'
produces:
- application/json
responses:
"200":
description: 更新成功
schema:
$ref: '#/definitions/util.ResponseAny'
"400":
description: 参数错误
schema:
$ref: '#/definitions/util.ResponseAny'
"401":
description: 未登录
schema:
$ref: '#/definitions/util.ResponseAny'
"403":
description: 无管理员权限
schema:
$ref: '#/definitions/util.ResponseAny'
"500":
description: 服务内部错误
schema:
$ref: '#/definitions/util.ResponseAny'
security:
- SessionCookie: []
summary: 更新缓存配置
tags:
- admin
/api/v1/admin/cache/status:
get:
description: 获取当前系统磁盘缓存的使用情况(已占用字节、Key 数量等)与策略配置
produces:
- application/json
responses:
"200":
description: 获取成功
schema:
allOf:
- $ref: '#/definitions/util.ResponseAny'
- properties:
data:
$ref: '#/definitions/diskcache.Status'
type: object
"401":
description: 未登录
schema:
$ref: '#/definitions/util.ResponseAny'
"403":
description: 无管理员权限
schema:
$ref: '#/definitions/util.ResponseAny'
"500":
description: 内部错误
schema:
$ref: '#/definitions/util.ResponseAny'
security:
- SessionCookie: []
summary: 获取缓存状态
tags:
- admin
/api/v1/admin/db-export:
get:
description: SQLite 时直接下载 .db 文件;PostgreSQL 时执行 pg_dump 并流式下载 .sql 文件,需要管理员权限