efficiently update bard convo hash
This commit is contained in:
parent
0c2a0e72b3
commit
d04d8f94dc
@ -6,14 +6,6 @@ type BardCache struct {
|
||||
Bards map[string]*Bard
|
||||
}
|
||||
|
||||
func GarbageCollectCache(cache *BardCache) {
|
||||
for k, v := range cache.Bards {
|
||||
if time.Since(v.LastInteractionTime) > time.Minute*5 {
|
||||
delete(cache.Bards, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cache *BardCache
|
||||
|
||||
func init() {
|
||||
|
@ -3,6 +3,7 @@ package bard
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
)
|
||||
|
||||
func HashConversation(conversation []string) string {
|
||||
@ -12,3 +13,18 @@ func HashConversation(conversation []string) string {
|
||||
}
|
||||
return hex.EncodeToString(hash.Sum(nil))
|
||||
}
|
||||
|
||||
func GarbageCollectCache(cache *BardCache) {
|
||||
for k, v := range cache.Bards {
|
||||
if time.Since(v.LastInteractionTime) > time.Minute*5 {
|
||||
delete(cache.Bards, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateBardHash(old_hash, hash string) {
|
||||
if _, ok := cache.Bards[old_hash]; ok {
|
||||
cache.Bards[hash] = cache.Bards[old_hash]
|
||||
delete(cache.Bards, old_hash)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user