1- // Copyright 2023 FishGoddess. All Rights Reserved.
1+ // Copyright 2025 FishGoddess. All Rights Reserved.
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
@@ -20,21 +20,17 @@ import (
2020 "time"
2121
2222 "github.com/FishGoddess/cachego"
23- "github.com/FishGoddess/cachego/pkg/clock "
23+ "github.com/FishGoddess/cachego/pkg/fastclock "
2424)
2525
2626func main () {
27- // Create a fast clock and get current time in nanosecond by Now.
28- c := clock .New ()
29- c .Now ()
30-
3127 // Fast clock may return an "incorrect" time compared with time.Now.
3228 // The gap will be smaller than about 100 ms.
3329 for i := 0 ; i < 10 ; i ++ {
3430 time .Sleep (time .Duration (rand .Int63n (int64 (time .Second ))))
3531
3632 timeNow := time .Now ().UnixNano ()
37- clockNow := c . Now ()
33+ clockNow := fastclock . NowNanos ()
3834
3935 fmt .Println (timeNow )
4036 fmt .Println (clockNow )
@@ -43,8 +39,8 @@ func main() {
4339 }
4440
4541 // You can specify the fast clock to cache by WithNow.
46- // All getting current time operations in this cache will use fast clock.
47- cache := cachego .NewCache (cachego .WithNow (clock . New (). Now ))
42+ // All time used in this cache will be got from fast clock.
43+ cache := cachego .NewCache (cachego .WithNow (fastclock . NowNanos ))
4844 cache .Set ("key" , 666 , 100 * time .Millisecond )
4945
5046 value , ok := cache .Get ("key" )
0 commit comments