Skip to content

Commit

Permalink
Merge pull request #370 from pb33f/v0.21.0
Browse files Browse the repository at this point in the history
v0.21.0
  • Loading branch information
daveshanley authored Feb 1, 2025
2 parents 26ed052 + 82fd263 commit 2b2d734
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
Binary file added .github/sponsors/apideck-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/sponsors/apideck-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ like our _very kind_ sponsors:

[scalar](https://scalar.com)

<a href="https://apideck.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".github/sponsors/apideck-dark.png">
<img alt="apideck'" src=".github/sponsors/apideck-light.png">
</picture>
</a>

[apideck](https://apideck.com)

---

Expand Down
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 2b2d734

Please sign in to comment.