feat: local cache

This commit is contained in:
withchao
2024-01-15 11:42:18 +08:00
parent 749eb11830
commit 3e30e50a09
7 changed files with 172 additions and 116 deletions
+3 -3
View File
@@ -14,18 +14,18 @@ type Cache[V any] interface {
func NewCache[V any](slotNum, slotSize int, successTTL, failedTTL time.Duration, target Target, onEvict EvictCallback[string, V]) Cache[V] {
c := &slot[V]{
n: uint64(slotNum),
slots: make([]*LRU[string, V], slotNum),
slots: make([]*InertiaLRU[string, V], slotNum),
target: target,
}
for i := 0; i < slotNum; i++ {
c.slots[i] = NewLRU[string, V](slotSize, successTTL, failedTTL, c.target, onEvict)
c.slots[i] = NewInertiaLRU[string, V](slotSize, successTTL, failedTTL, c.target, onEvict)
}
return c
}
type slot[V any] struct {
n uint64
slots []*LRU[string, V]
slots []*InertiaLRU[string, V]
target Target
}