Documentation
¶
Index ¶
- Constants
- func Decode(value uint64) string
- func Encode(ip string) uint64
- func ForceGC()
- func IPStr2Int(s string) uint32
- func Init()
- func IntToIP(v uint32) string
- func IsDebugMode() bool
- func Query(p *QueryParam) map[uint64]int
- func Save(p *SaveParam)
- func SetDebugMode(t bool)
- func SetDefaultQueryTopK(k int)
- func SetExpireDuration(d time.Duration)
- func SetGcInterval(d time.Duration)
- type CachePool
- type MinHeap
- type MinHeapEntry
- type ModelQueryRequest
- type QueryParam
- type RadixNode
- type RadixTree
- type RadixTreeInfo
- type RadixTreeLevelInfo
- type SaveParam
- type StackRadixNode
- type StackRadixNodeHandle
- type TopKMap
Constants ¶
const ( DefaultExpireDuration = time.Hour DefaultGcInterval = 24 * time.Hour DefaultTopK = 5 )
Default configuration constants
Variables ¶
This section is empty.
Functions ¶
func Query ¶
func Query(p *QueryParam) map[uint64]int
Query searches the cache for matching entries based on prompt or prompt hash
func SetDefaultQueryTopK ¶
func SetDefaultQueryTopK(k int)
SetDefaultQueryTopK sets the default TopK value for queries
func SetExpireDuration ¶
SetExpireDuration sets the expiration duration for cache entries
func SetGcInterval ¶
SetGcInterval sets the garbage collection interval
Types ¶
type CachePool ¶
type CachePool struct {
// contains filtered or unexported fields
}
CachePool manages multiple cache instances using radix trees
type MinHeap ¶
type MinHeap []*MinHeapEntry
MinHeap implements heap.Interface for maintaining top-K elements
type MinHeapEntry ¶
type MinHeapEntry struct {
// contains filtered or unexported fields
}
MinHeapEntry represents an entry in the min-heap with key-value pair and index
type ModelQueryRequest ¶
type ModelQueryRequest struct {
Cluster string `json:"cluster" form:"cluster" binding:"required"`
}
ModelQueryRequest defines parameters for model tree information queries
type QueryParam ¶
type QueryParam struct {
Cluster string `json:"cluster" form:"cluster" binding:"required"`
PromptHash []uint64 `json:"prompt_hash" binding:"required"`
// TopK represents the maximum number of results to return, 0 means use default configuration value
TopK int `json:"top_k"`
}
QueryParam defines parameters for cache query operations
type RadixNode ¶
type RadixNode struct {
// contains filtered or unexported fields
}
func NewRadixNode ¶
type RadixTree ¶
type RadixTree struct {
// contains filtered or unexported fields
}
RadixTree implements a radix tree for efficient prefix-based storage and retrieval
func NewRadixTree ¶
NewRadixTree creates a new radix tree with the given name
func (*RadixTree) CleanExpireNode ¶
func (t *RadixTree) CleanExpireNode()
CleanExpireNode is a wrapper for traversal calls
func (*RadixTree) GetTreeInfo ¶
func (t *RadixTree) GetTreeInfo() *RadixTreeInfo
GetTreeInfo gets information from the last traversal
func (*RadixTree) Insert ¶
Insert adds a data entry to the radix tree All matching nodes during tree traversal need to insert data data is the unique index, value is the corresponding value (currently not needed)
func (*RadixTree) MatchAll ¶
MatchAll returns all data that matches the common prefix of the key Returns: {data, matched prefix length} Currently uses uint64(ip32+ip32) to represent data, may need adjustment if adding content later
func (*RadixTree) Traversal ¶
func (t *RadixTree) Traversal(handle StackRadixNodeHandle)
Traversal performs level-order traversal of the entire tree and calls handle for each node
type RadixTreeInfo ¶
type RadixTreeInfo struct {
Info map[int]*RadixTreeLevelInfo `json:"info"` // Level information by depth
UpdateTime time.Time `json:"update_time"` // Last update timestamp
}
RadixTreeInfo contains aggregated information about the radix tree
func ModelQuery ¶
func ModelQuery(p *ModelQueryRequest) *RadixTreeInfo
ModelQuery retrieves radix tree information for a specific cluster
type RadixTreeLevelInfo ¶
type RadixTreeLevelInfo struct {
NodesCount int `json:"nodes_count"` // Number of nodes at this level
PrefixTotal int `json:"prefix_total"` // Total prefix count at this level
MaxPrefixLen int `json:"max_prefix_len"` // Maximum prefix length at this level
MinPrefixLen int `json:"min_prefix_len"` // Minimum prefix length at this level
}
RadixTreeLevelInfo contains statistics for a specific level in the radix tree
type SaveParam ¶
type SaveParam struct {
Cluster string `json:"cluster" form:"cluster" binding:"required"`
PromptHash []uint64 `json:"prompt_hash" binding:"required"`
IP string `json:"ip" binding:"required,ipv4"`
}
SaveParam defines parameters for cache save operations
type StackRadixNode ¶
type StackRadixNode struct {
// contains filtered or unexported fields
}
type StackRadixNodeHandle ¶
type StackRadixNodeHandle func(current *RadixNode, n *StackRadixNode) bool
StackRadixNodeHandle processes corresponding node information during traversal If returns false, this node will no longer participate in subsequent traversal Usage: During global GC, if node has expired, skip traversing subsequent nodes Node processing in Handle doesn't require locking, default traversal has full tree lock
type TopKMap ¶
type TopKMap struct {
// contains filtered or unexported fields
}
TopKMap maintains top-K largest values using a min-heap TODO: Optimization potential - may not need min-heap directly due to RadixTree patterns
func NewTopKMap ¶
NewTopKMap creates a new TopKMap with specified capacity