Debian Codegraph @

policy/clock/example_test.go

raw symbols SCIP
1 package clock_test
2
3 import (
4 "fmt"
5
6 "github.com/Code-Hex/go-generics-cache/policy/clock"
7 )
8
9 func ExampleNewCache() {
10 c := clock.NewCache[string, int]()
11 c.Set("a", 1)
12 c.Set("b", 2)
13 av, aok := c.Get("a")
14 bv, bok := c.Get("b")
15 cv, cok := c.Get("c")
16 fmt.Println(av, aok)
17 fmt.Println(bv, bok)
18 fmt.Println(cv, cok)
19 c.Delete("a")
20 _, aok2 := c.Get("a")
21 if !aok2 {
22 fmt.Println("key 'a' has been deleted")
23 }
24 // update
25 c.Set("b", 3)
26 newbv, _ := c.Get("b")
27 fmt.Println(newbv)
28 // Output:
29 // 1 true
30 // 2 true
31 // 0 false
32 // key 'a' has been deleted
33 // 3
34 }
35
36 func ExampleCache_Keys() {
37 c := clock.NewCache[string, int]()
38 c.Set("foo", 1)
39 c.Set("bar", 2)
40 c.Set("baz", 3)
41 keys := c.Keys()
42 for _, key := range keys {
43 fmt.Println(key)
44 }
45 // Output:
46 // foo
47 // bar
48 // baz
49 }