Skip to content

Commit 7589200

Browse files
committed
feat(cache): directly use contatenation of prompt and suffix as key
1 parent ba4e5e3 commit 7589200

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

cache/cache.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cache
22

33
import (
4-
"crypto/sha256"
54
"llm-language-server/lsp"
65
"time"
76
)
@@ -24,28 +23,20 @@ func checkExpiredKeys() {
2423
}
2524
}
2625

27-
func getKey(prompt string, suffix string) string {
28-
cacheKeyHash := sha256.New()
29-
cacheKeyHash.Write([]byte(prompt + "_" + suffix))
30-
return string(cacheKeyHash.Sum(nil))
31-
}
32-
3326
func Set(prompt string, suffix string, value []lsp.CompletionItem) {
3427
if !started {
3528
return
3629
}
3730

38-
key := getKey(prompt, suffix)
39-
cacheMap[key] = CacheValue{Data: value, Ex: time.Now().Add(ex)}
31+
cacheMap[prompt+suffix] = CacheValue{Data: value, Ex: time.Now().Add(ex)}
4032
}
4133

4234
func Get(prompt string, suffix string) ([]lsp.CompletionItem, bool) {
4335
if !started {
4436
return nil, false
4537
}
4638

47-
key := getKey(prompt, suffix)
48-
value, exists := cacheMap[key]
39+
value, exists := cacheMap[prompt+suffix]
4940

5041
if exists {
5142
return value.Data, true

0 commit comments

Comments
 (0)