...
1 package main
2
3 import (
4 "flag"
5 "fmt"
6 "golang.conradwood.net/go-easyops/cache"
7 "golang.conradwood.net/go-easyops/server"
8 "time"
9 )
10
11 var (
12 ch = cache.New("testcache", time.Duration(1)*time.Second, 999)
13 )
14
15 func main() {
16 flag.Parse()
17
18 server.StartFakeService("fakeservice_testcache")
19 key := "FOOKEY"
20 started := time.Now()
21 for {
22 diff := time.Since(started).Seconds()
23 ds := fmt.Sprintf("%00.2f ", diff)
24 o := ch.Get(key)
25 if o == nil {
26 fmt.Printf("%sNo cache entry\n", ds)
27 ch.Put(key, "foo")
28 } else {
29 fmt.Printf("%sGot value\n", ds)
30 }
31 time.Sleep(time.Duration(250) * time.Millisecond)
32 }
33 }
34
View as plain text