@@ -11,27 +11,27 @@ import (
1111// Expired items are not automatically removed.
1212//
1313// 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 {
1515 mu sync.Mutex
16- m map [string ]* lruItem [K , V ]
16+ m map [K ]* lruItem [K , V ]
1717 head , tail * lruItem [K , V ]
1818 cap uint
1919}
2020
2121type lruItem [K comparable , V any ] struct {
22- key string
22+ key K
2323 value V
2424 time time.Time
2525 prev , next * lruItem [K , V ]
2626}
2727
2828// 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 }
3131}
3232
3333// 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 {
3535 _ = ctx
3636
3737 l .mu .Lock ()
@@ -47,7 +47,7 @@ func (l *LRU[K, V]) Delete(ctx context.Context, key string) error {
4747}
4848
4949// 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 ) {
5151 _ = ctx
5252
5353 l .mu .Lock ()
@@ -75,7 +75,7 @@ func (l *LRU[K, V]) Len() int {
7575// Set implements the [Backend] interface.
7676//
7777// 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 {
7979 _ = ctx
8080
8181 l .mu .Lock ()
0 commit comments