MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / GetCachedSignatureRequired

Function GetCachedSignatureRequired

internal/cache/signature_cache.go:168–236  ·  view source on GitHub ↗

GetCachedSignatureRequired retrieves a cached signature for request-time paths.

(ctx context.Context, modelName, text string)

Source from the content-addressed store, hash-verified

166
167// GetCachedSignatureRequired retrieves a cached signature for request-time paths.
168func GetCachedSignatureRequired(ctx context.Context, modelName, text string) (string, error) {
169 groupKey := GetModelGroup(modelName)
170
171 if text == "" {
172 if groupKey == "gemini" {
173 return "skip_thought_signature_validator", nil
174 }
175 return "", nil
176 }
177
178 if client, homeMode, errClient := currentSignatureKVClient(); homeMode {
179 if errClient != nil {
180 return "", errClient
181 }
182 key := signatureKVKey(modelName, text)
183 raw, found, errGet := client.KVGet(ctx, key)
184 if errGet != nil {
185 return "", errGet
186 }
187 if !found {
188 if groupKey == "gemini" {
189 return "skip_thought_signature_validator", nil
190 }
191 return "", nil
192 }
193 if _, errExpire := client.KVExpire(ctx, key, SignatureCacheTTL); errExpire != nil {
194 return "", errExpire
195 }
196 return string(raw), nil
197 }
198
199 val, ok := signatureCache.Load(groupKey)
200 if !ok {
201 if groupKey == "gemini" {
202 return "skip_thought_signature_validator", nil
203 }
204 return "", nil
205 }
206 sc := val.(*groupCache)
207
208 textHash := hashText(text)
209
210 now := time.Now()
211
212 sc.mu.Lock()
213 entry, exists := sc.entries[textHash]
214 if !exists {
215 sc.mu.Unlock()
216 if groupKey == "gemini" {
217 return "skip_thought_signature_validator", nil
218 }
219 return "", nil
220 }
221 if now.Sub(entry.Timestamp) > SignatureCacheTTL {
222 delete(sc.entries, textHash)
223 sc.mu.Unlock()
224 if groupKey == "gemini" {
225 return "skip_thought_signature_validator", nil

Calls 6

GetModelGroupFunction · 0.85
signatureKVKeyFunction · 0.85
hashTextFunction · 0.85
KVGetMethod · 0.65
KVExpireMethod · 0.65
LoadMethod · 0.65