@@ -11,27 +11,27 @@ import (
11
11
// Expired items are not automatically removed.
12
12
//
13
13
// TODO: Use maphash.Comparable in Go 1.24 and allow the key to be configured.
14
- type LRU [K comparable , V any ] struct {
14
+ type LRU [K string , V any ] struct {
15
15
mu sync.Mutex
16
- m map [string ]* lruItem [K , V ]
16
+ m map [K ]* lruItem [K , V ]
17
17
head , tail * lruItem [K , V ]
18
18
cap uint
19
19
}
20
20
21
21
type lruItem [K comparable , V any ] struct {
22
- key string
22
+ key K
23
23
value V
24
24
time time.Time
25
25
prev , next * lruItem [K , V ]
26
26
}
27
27
28
28
// NewLRU returns an in-memory cache [Adapter] using an implementation of an LRU algorithm.
29
- func NewLRU [K comparable , V any ](size uint ) * LRU [K , V ] {
30
- return & LRU [K , V ]{m : make (map [string ]* lruItem [K , V ]), cap : size }
29
+ func NewLRU [K string , V any ](size uint ) * LRU [K , V ] {
30
+ return & LRU [K , V ]{m : make (map [K ]* lruItem [K , V ]), cap : size }
31
31
}
32
32
33
33
// Delete removes the entry with the given key from the cache.
34
- func (l * LRU [K , V ]) Delete (ctx context.Context , key string ) error {
34
+ func (l * LRU [K , V ]) Delete (ctx context.Context , key K ) error {
35
35
_ = ctx
36
36
37
37
l .mu .Lock ()
@@ -47,7 +47,7 @@ func (l *LRU[K, V]) Delete(ctx context.Context, key string) error {
47
47
}
48
48
49
49
// Get implements the [Backend] interface.
50
- func (l * LRU [K , V ]) Get (ctx context.Context , key string ) (value V , age time.Duration , err error ) {
50
+ func (l * LRU [K , V ]) Get (ctx context.Context , key K ) (value V , age time.Duration , err error ) {
51
51
_ = ctx
52
52
53
53
l .mu .Lock ()
@@ -75,7 +75,7 @@ func (l *LRU[K, V]) Len() int {
75
75
// Set implements the [Backend] interface.
76
76
//
77
77
// If the weight of the value is greater than the size of the LRU, the value will be discarded.
78
- func (l * LRU [K , V ]) Set (ctx context.Context , key string , value V ) error {
78
+ func (l * LRU [K , V ]) Set (ctx context.Context , key K , value V ) error {
79
79
_ = ctx
80
80
81
81
l .mu .Lock ()
0 commit comments