feat: msg local cache

This commit is contained in:
withchao
2024-01-08 16:47:39 +08:00
parent 1ae523dcc2
commit 3d77c1c8cf
6 changed files with 63 additions and 26 deletions
+8 -2
View File
@@ -14,8 +14,14 @@ type waitItem[V any] struct {
value V
}
func NewLRU[K comparable, V any](size int, successTTL, failedTTL time.Duration, target Target) *LRU[K, V] {
core, err := simplelru.NewLRU[K, *waitItem[V]](size, nil)
func NewLRU[K comparable, V any](size int, successTTL, failedTTL time.Duration, target Target, onEvict EvictCallback[K, V]) *LRU[K, V] {
var cb simplelru.EvictCallback[K, *waitItem[V]]
if onEvict != nil {
cb = func(key K, value *waitItem[V]) {
onEvict(key, value.value)
}
}
core, err := simplelru.NewLRU[K, *waitItem[V]](size, cb)
if err != nil {
panic(err)
}