From 5820feb7f58073d0b8bd1fb54e99238a10dc5ba7 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 26 Jan 2024 13:24:09 -0600 Subject: [PATCH] Fix hard coded types after generics switch. References: https://todo.code.netlandish.com/~netlandish/gobwebs/7 --- cache/cache.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 1a74a2c..562c80e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -15,18 +15,18 @@ type Cache[K comparable, V any] interface { // DummyCache is a super dumb in memory cache store. type DummyCache[K comparable, V any] struct { - cache map[string]any + cache map[K]V limit int } // Get fetches a specific key from the cache -func (d *DummyCache[K, V]) Get(key string) (any, error) { +func (d *DummyCache[K, V]) Get(key K) (any, error) { val := d.cache[key] return val, nil } // Set will set a key/value in the cache backend. -func (d *DummyCache[K, V]) Set(key string, value any) (bool, error) { +func (d *DummyCache[K, V]) Set(key K, value V) (bool, error) { var evicted bool if len(d.cache) >= d.limit { for k := range d.cache { @@ -42,7 +42,7 @@ func (d *DummyCache[K, V]) Set(key string, value any) (bool, error) { } // Delete will delete a key from the cache -func (d *DummyCache[K, V]) Delete(key string) (bool, error) { +func (d *DummyCache[K, V]) Delete(key K) (bool, error) { var present bool if _, ok := d.cache[key]; ok { present = true @@ -59,7 +59,7 @@ func NewDummyCache[K comparable, V any](limit int) *DummyCache[K, V] { limit = 10 } return &DummyCache[K, V]{ - cache: make(map[string]any), + cache: make(map[K]V), limit: limit, } } -- 2.43.0