Skip to content

Commit

Permalink
- fixed timeCacher
Browse files Browse the repository at this point in the history
- added compiling protection to all cachers
  • Loading branch information
iulianpascalau committed Oct 25, 2023
1 parent 9b7d17c commit 00f58ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lrucache/lrucache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var _ types.Cacher = (*lruCache)(nil)

var log = logger.GetOrCreate("storage/lrucache")
var _ types.Cacher = (*lruCache)(nil)

// LRUCache implements a Least Recently Used eviction cache
type lruCache struct {
Expand Down
2 changes: 2 additions & 0 deletions rtcache/removalTrackingCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type removalTrackingCache struct {
removalCache types.Cacher
}

var _ types.Cacher = (*removalTrackingCache)(nil)

// NewRemovalTrackingCache will create a new instance of a cache that is able to track removal events
func NewRemovalTrackingCache(mainCache types.Cacher, removalCache types.Cacher) (*removalTrackingCache, error) {
if check.IfNil(mainCache) {
Expand Down
1 change: 1 addition & 0 deletions storageCacherAdapter/storageCacherAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

var log = logger.GetOrCreate("storageCacherAdapter")
var _ types.Cacher = (*storageCacherAdapter)(nil)

type storageCacherAdapter struct {
cacher types.AdaptedSizedLRUCache
Expand Down
7 changes: 7 additions & 0 deletions timecache/timeCacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (

logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-storage-go/common"
"github.com/multiversx/mx-chain-storage-go/types"
)

var log = logger.GetOrCreate("storage/timecache")
var _ types.Cacher = (*timeCacher)(nil)

const minDuration = time.Second

Expand Down Expand Up @@ -206,6 +208,11 @@ func (tc *timeCacher) callAddedDataHandlers(key []byte, value interface{}) {
tc.mutAddedDataHandlers.RUnlock()
}

// GetRemovalStatus will return the unknown status because this implementation does not track removed keys
func (c *timeCacher) GetRemovalStatus(_ []byte) types.RemovalStatus {
return types.UnknownRemovalStatus
}

// Close will close the internal sweep go routine
func (tc *timeCacher) Close() error {
if tc.cancelFunc != nil {
Expand Down
8 changes: 8 additions & 0 deletions timecache/timeCacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/multiversx/mx-chain-storage-go/common"
"github.com/multiversx/mx-chain-storage-go/timecache"
"github.com/multiversx/mx-chain-storage-go/types"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -363,6 +364,13 @@ func TestTimeCacher_MaxSize(t *testing.T) {
assert.Equal(t, math.MaxInt32, cacher.MaxSize())
}

func TestTimeCacher_GetRemovalStatus(t *testing.T) {
t.Parallel()

cacher, _ := timecache.NewTimeCacher(createArgTimeCacher())
assert.Equal(t, types.UnknownRemovalStatus, cacher.GetRemovalStatus(nil))
}

func TestTimeCacher_ConcurrentOperations(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 00f58ef

Please sign in to comment.