diff --git a/pkg/storage/cache/cache_test.go b/pkg/storage/cache/cache_test.go index 75f125b2..491e242f 100644 --- a/pkg/storage/cache/cache_test.go +++ b/pkg/storage/cache/cache_test.go @@ -39,7 +39,7 @@ func TestLRUCache(t *testing.T) { t.Errorf("failed load %d", i) return } - if !bytes.Equal(val, []byte(fmt.Sprintf("_%d_", i))) { + if !bytes.Equal(val.([]byte), []byte(fmt.Sprintf("_%d_", i))) { t.Errorf("value is incorrect %d", i) return } diff --git a/pkg/storage/cache/lru.go b/pkg/storage/cache/lru.go index 3cb5005e..a2fa42dd 100644 --- a/pkg/storage/cache/lru.go +++ b/pkg/storage/cache/lru.go @@ -12,7 +12,7 @@ var ( type sLRUCache struct { fMutex sync.RWMutex - fMap map[string][]byte + fMap map[string]interface{} fQueue []string fIndex uint64 } @@ -20,7 +20,7 @@ type sLRUCache struct { func NewLRUCache(pCapacity uint64) ILRUCache { return &sLRUCache{ fQueue: make([]string, pCapacity), - fMap: make(map[string][]byte, pCapacity), + fMap: make(map[string]interface{}, pCapacity), } } @@ -43,7 +43,7 @@ func (p *sLRUCache) GetKey(i uint64) ([]byte, bool) { return hash, len(hash) != 0 } -func (p *sLRUCache) Get(pKey []byte) ([]byte, bool) { +func (p *sLRUCache) Get(pKey []byte) (interface{}, bool) { p.fMutex.RLock() defer p.fMutex.RUnlock() @@ -51,13 +51,13 @@ func (p *sLRUCache) Get(pKey []byte) ([]byte, bool) { return val, ok } -func (p *sLRUCache) Set(pKey, pValue []byte) bool { +func (p *sLRUCache) Set(pKey []byte, pValue interface{}) bool { p.fMutex.Lock() defer p.fMutex.Unlock() // hash already exists in queue - hexKey := encoding.HexEncode(pKey) - if _, ok := p.fMap[hexKey]; ok { + key := encoding.HexEncode(pKey) + if _, ok := p.fMap[key]; ok { return false } @@ -65,8 +65,8 @@ func (p *sLRUCache) Set(pKey, pValue []byte) bool { delete(p.fMap, p.fQueue[p.fIndex]) // push hash to queue - p.fQueue[p.fIndex] = hexKey - p.fMap[hexKey] = pValue + p.fQueue[p.fIndex] = key + p.fMap[key] = pValue // increment queue index p.fIndex = (p.fIndex + 1) % uint64(len(p.fQueue)) diff --git a/pkg/storage/cache/types.go b/pkg/storage/cache/types.go index 2c7f3fd8..a238dbd2 100644 --- a/pkg/storage/cache/types.go +++ b/pkg/storage/cache/types.go @@ -13,9 +13,9 @@ type ICache interface { } type ICacheSetter interface { - Set([]byte, []byte) bool + Set([]byte, interface{}) bool } type ICacheGetter interface { - Get([]byte) ([]byte, bool) + Get([]byte) (interface{}, bool) }