Skip to content

Commit

Permalink
feat(cache): GetKeys() -> Keys()
Browse files Browse the repository at this point in the history
  • Loading branch information
clambin committed Aug 24, 2024
1 parent b613b00 commit c8f6523
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,20 @@ func (c *Cache[K, V]) GetAndRemove(key K) (V, bool) {
}

// GetKeys returns all keys in the cache.
//
// Deprecated: use Keys() instead
func (c *Cache[K, V]) GetKeys() (keys []K) {
return c.Keys()
}

func (c *Cache[K, V]) Keys() []K {
c.lock.RLock()
defer c.lock.RUnlock()

keys := make([]K, 0, len(c.values))
for key := range c.values {
keys = append(keys, key)
}
return
return keys
}

// Size returns the current size of the cache. Expired items are counted
Expand Down
4 changes: 3 additions & 1 deletion cache/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/clambin/go-common/cache

go 1.21
go 1.22

toolchain go1.22.6
2 changes: 1 addition & 1 deletion http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/clambin/go-common/cache v0.5.0
github.com/clambin/go-common/testutils v0.1.0
github.com/prometheus/client_golang v1.20.1
github.com/prometheus/client_golang v1.20.2
golang.org/x/sync v0.8.0
)

Expand Down
2 changes: 2 additions & 0 deletions http/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/prometheus/client_golang v1.20.1 h1:IMJXHOD6eARkQpxo8KkhgEVFlBNm+nkrFUyGlIu7Na8=
github.com/prometheus/client_golang v1.20.1/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
Expand Down

0 comments on commit c8f6523

Please # to comment.