Skip to content

Commit

Permalink
Addressed issue #365
Browse files Browse the repository at this point in the history
Removed non atomic code. Breaking changes too.
  • Loading branch information
daveshanley committed Feb 1, 2025
1 parent 26ed052 commit 794c743
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
21 changes: 2 additions & 19 deletions index/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

// SetCache sets a sync map as a temporary cache for the index.
// TODO: this needs to be moved to the Cache interface.
func (index *SpecIndex) SetCache(sync *sync.Map) {
index.cache = sync
}
Expand Down Expand Up @@ -55,8 +54,6 @@ type Cache interface {
GetStore() *sync.Map
AddHit() uint64
AddMiss() uint64
SetHits(uint64) uint64
SetMisses(uint64) uint64
GetHits() uint64
GetMisses() uint64
Clear()
Expand Down Expand Up @@ -100,26 +97,12 @@ func (c *SimpleCache) Store(key, value any) {

// AddHit increments the hit counter by one, and returns the current value of hits.
func (c *SimpleCache) AddHit() uint64 {
c.hits.Add(1)
return c.hits.Load()
return c.hits.Add(1)
}

// AddMiss increments the miss counter by one, and returns the current value of misses.
func (c *SimpleCache) AddMiss() uint64 {
c.misses.Add(1)
return c.hits.Load()
}

// SetHits sets the hit counter to the provided value, and returns the current value of hits.
func (c *SimpleCache) SetHits(hits uint64) uint64 {
c.hits.Add(hits)
return c.hits.Load()
}

// SetMisses sets the miss counter to the provided value, and returns the current value of misses.
func (c *SimpleCache) SetMisses(misses uint64) uint64 {
c.misses.Add(misses)
return c.misses.Load()
return c.misses.Add(1)
}

// GetHits returns the current value of hits.
Expand Down
14 changes: 0 additions & 14 deletions index/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ func TestAddMiss(t *testing.T) {
assert.Equal(t, initialMisses+1, newMisses)
}

// TestSetHits tests that the hit counter is correctly set.
func TestSetHits(t *testing.T) {
cache := CreateNewCache()
cache.SetHits(10)
assert.Equal(t, uint64(10), cache.GetHits())
}

// TestSetMisses tests that the miss counter is correctly set.
func TestSetMisses(t *testing.T) {
cache := CreateNewCache()
cache.SetMisses(5)
assert.Equal(t, uint64(5), cache.GetMisses())
}

// TestClear tests that the cache is correctly cleared.
func TestClear(t *testing.T) {
cache := CreateNewCache()
Expand Down

0 comments on commit 794c743

Please sign in to comment.