MCPcopy Create free account
hub / github.com/astercloud/aster / GenerateKey

Method GenerateKey

pkg/tools/cache.go:117–128  ·  view source on GitHub ↗

GenerateKey 生成缓存键

(toolName string, input map[string]any)

Source from the content-addressed store, hash-verified

115
116// GenerateKey 生成缓存键
117func (c *ToolCache) GenerateKey(toolName string, input map[string]any) string {
118 // 序列化输入参数
119 data, err := json.Marshal(input)
120 if err != nil {
121 // 如果序列化失败,使用简单的字符串拼接
122 return fmt.Sprintf("%s_%v", toolName, input)
123 }
124
125 // 计算 SHA256 哈希
126 hash := sha256.Sum256(data)
127 return fmt.Sprintf("%s_%x", toolName, hash[:16]) // 使用前16字节
128}
129
130// Get 获取缓存
131func (c *ToolCache) Get(ctx context.Context, key string) (any, bool) {

Callers 5

TestToolCache_ClearFunction · 0.95
TestToolCache_CleanupFunction · 0.95
ExecuteMethod · 0.80

Calls

no outgoing calls

Tested by 4

TestToolCache_ClearFunction · 0.76
TestToolCache_CleanupFunction · 0.76