@@ 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,
}
}