Skip to content

Commit 0edcc43

Browse files
authored
Update go 1.23 (#74)
1 parent 985ae5c commit 0edcc43

15 files changed

+62
-517
lines changed

cache/cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ func (c *Cache[Key, Value]) Swap(key Key, value Value) (previous Value, loaded b
124124
return
125125
}
126126

127-
// Empty deletes all values in cache.
128-
func (c *Cache[Key, Value]) Empty() {
127+
// Clear deletes all values in cache.
128+
func (c *Cache[Key, Value]) Clear() {
129129
c.m.Range(func(k Key, i *item[Value]) bool {
130130
c.m.Delete(k)
131131
i.Lock()

cache/cache_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestEmpty(t *testing.T) {
3939
t.Error("expected ok; got not")
4040
}
4141
}
42-
cache.Empty()
42+
cache.Clear()
4343
for _, i := range []string{"a", "b", "c"} {
4444
if _, ok := cache.Get(i); ok {
4545
t.Error("expected not ok; got ok")
@@ -49,7 +49,7 @@ func TestEmpty(t *testing.T) {
4949

5050
func TestRenew(t *testing.T) {
5151
cache := New[string, string](true)
52-
defer cache.Empty()
52+
defer cache.Clear()
5353
expire := make(chan struct{})
5454
cache.Set("renew", "old", 2*time.Second, func() (string, error) {
5555
defer func() { close(expire) }()

cache/map.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ func (m *Map[Key, Value]) Store(key Key, value Value) {
2626
m.m.Store(key, value)
2727
}
2828

29+
// Clear deletes all the entries, resulting in an empty Map.
30+
func (m *Map[Key, Value]) Clear() {
31+
m.m.Clear()
32+
}
33+
2934
// LoadOrStore returns the existing value for the key if present.
3035
// Otherwise, it stores and returns the given value.
3136
// The loaded result is true if the value was loaded, false if stored.
3237
func (m *Map[Key, Value]) LoadOrStore(key Key, value Value) (actual Value, loaded bool) {
3338
var v any
34-
if v, loaded = m.m.LoadOrStore(key, value); v != nil {
35-
actual = v.(Value)
39+
if v, loaded = m.m.LoadOrStore(key, value); loaded {
40+
if v != nil {
41+
actual = v.(Value)
42+
}
43+
} else {
44+
actual = value
3645
}
3746
return
3847
}
@@ -92,10 +101,10 @@ func (m *Map[Key, Value]) CompareAndDelete(key Key, old Value) (deleted bool) {
92101
func (m *Map[Key, Value]) Range(f func(Key, Value) bool) {
93102
m.m.Range(func(key, value any) bool {
94103
var k Key
104+
var v Value
95105
if key != nil {
96106
k = key.(Key)
97107
}
98-
var v Value
99108
if value != nil {
100109
v = value.(Value)
101110
}

cache/map_reference_test.go

-274
This file was deleted.

0 commit comments

Comments
 (0)