~netlandish/gobwebs

5820feb7f58073d0b8bd1fb54e99238a10dc5ba7 — Peter Sanchez 9 months ago f1463b0
Fix hard coded types after generics switch.

References: https://todo.code.netlandish.com/~netlandish/gobwebs/7
1 files changed, 5 insertions(+), 5 deletions(-)

M cache/cache.go
M cache/cache.go => cache/cache.go +5 -5
@@ 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,
	}
}