| 1 |
package fifo_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/Code-Hex/go-generics-cache/policy/fifo" |
| 7 |
) |
| 8 |
|
| 9 |
func ExampleNewCache() { |
| 10 |
c := fifo.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 |
|
| 25 |
c.Set("b", 3) |
| 26 |
newbv, _ := c.Get("b") |
| 27 |
fmt.Println(newbv) |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
func ExampleCache_Keys() { |
| 37 |
c := fifo.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 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
} |