cache

package
v0.0.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(snapshots []AgentSnapshot) map[string]ClusterEntityStats

Aggregate 把多个 agent 的快照按 union-of-keys 聚合——后端不再硬编码实体清单, 任何 agent 上报的新缓存 key 自动流通。lru 类算 hit_rate/util;index 类只求和 Size/Extra。

Types

type AgentCacheSnapshot

type AgentCacheSnapshot struct {
	AgentID    string                               `json:"agent_id"`
	Name       string                               `json:"name"`
	Online     bool                                 `json:"online"`
	LastSeen   int64                                `json:"last_seen"`
	CacheStats map[string]protocol.CacheEntityStats `json:"cache_stats,omitempty"`
}

AgentCacheSnapshot 是单 agent 在 /api/admin/cache/stats 响应里的一项。

type AgentSnapshot

type AgentSnapshot struct {
	AgentID    string
	Online     bool
	CacheStats map[string]protocol.CacheEntityStats
}

AgentSnapshot 是某个 agent 的 cache 快照与在线状态。Online==false 的 agent 跳过。

type ClusterEntityStats

type ClusterEntityStats struct {
	Kind          string           `json:"kind,omitempty"`
	Hits          int64            `json:"hits"`
	Misses        int64            `json:"misses"`
	Evictions     int64            `json:"evictions"`
	NegativeHits  int64            `json:"negative_hits"`
	LoadErrors    int64            `json:"load_errors"`
	Invalidations int64            `json:"invalidations"`
	Size          int              `json:"size"`
	Capacity      int              `json:"capacity"`
	Extra         map[string]int64 `json:"extra,omitempty"`
	HitRate       *float64         `json:"hit_rate"`
	Util          *float64         `json:"util"`
}

ClusterEntityStats 是单实体/索引跨 agent 聚合后的结果。 HitRate/Util 仅 lru 类且分母>0 时非 nil(前端渲染 "—")。

type Handler

type Handler struct {
	GetOnlineAgentIDs func() []string
	GetRuntime        func(agentID string) *msync.AgentRuntime
	// Tracker 用于 EnrichLastSeen,覆盖 stats 中 agent 的 last_seen。
	// nil 时跳过 enrich(DB 值 fallback)。
	Tracker *msync.HeartbeatTracker
}

Handler 依赖 Hub 提供 online 列表 + per-agent runtime; 用 DAO 把 agent_id → name 拼出来。

func (*Handler) Stats

func (h *Handler) Stats(c *app.Context, _ api.EmptyRequest) (StatsResponse, error)

Stats 返回所有 agent 的 cache 快照 + 集群聚合。

online 仅以 Hub 的 WebSocket 连接为准(Hub.IsOnline 等价于 "这个 agent_id 在 GetOnlineAgentIDs 返回值里"),不依赖 last_seen。 offline agent 也会列在 agents[] 里(带最近 last_seen),但 不计入 cluster 聚合。

type StatsResponse

type StatsResponse struct {
	Agents  []AgentCacheSnapshot          `json:"agents"`
	Cluster map[string]ClusterEntityStats `json:"cluster"`
}

StatsResponse 是 /api/admin/cache/stats 的整体响应。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL