We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7e0286a commit 5605c5eCopy full SHA for 5605c5e
cache/noop.go
@@ -0,0 +1,7 @@
1
+package cache
2
+
3
+// Noop discards all writes and load always fails. useful for tests for example.
4
+type Noop[K, V any] struct{}
5
6
+func (_ Noop[K, V]) Load(_ K) (value V, loaded bool) { return }
7
+func (_ Noop[K, V]) Store(_ K, _ V) {}
cache/noop_test.go
@@ -0,0 +1,17 @@
+import "testing"
+func TestNoop(t *testing.T) {
+ t.Run("Implements Cacher", func(t *testing.T) {
+ var _ Cacher[any, any] = Noop[any, any]{}
8
+ })
9
10
+ t.Run("Discards writes", func(t *testing.T) {
11
+ c := Noop[string, int]{}
12
+ c.Store("k1", 1)
13
+ v, loaded := c.Load("k1")
14
+ assertEqual(t, 0, v)
15
+ assertEqual(t, false, loaded)
16
17
+}
0 commit comments