@@ -18,15 +18,10 @@ Package cachego provides an easy way to use foundation for your caching operatio
18181. basic:
1919
2020 // Use NewCache function to create a cache.
21- // You can use WithLRU to specify the type of cache to lru.
22- // Also, try WithLFU if you want to use lfu to evict data.
23- cache := cachego.NewCache(cachego.WithLRU(100))
24- cache = cachego.NewCache(cachego.WithLFU(100))
25-
2621 // By default, it creates a standard cache which evicts entries randomly.
2722 // Use WithShardings to shard cache to several parts for higher performance.
28- cache = cachego.NewCache(cachego.WithShardings(64))
29- cache = cachego.NewCache()
23+ // Use WithGC to clean expired entries every 10 minutes.
24+ cache : = cachego.NewCache(cachego.WithGC(10*time.Minute), cachego.WithShardings(64) )
3025
3126 // Set an entry to cache with ttl.
3227 cache.Set("key", 123, time.Second)
@@ -57,13 +52,19 @@ Package cachego provides an easy way to use foundation for your caching operatio
5752 value, ok = cache.Get("key")
5853 if !ok {
5954 // Loaded entry will be set to cache and returned.
55+ // By default, it will use singleflight.
6056 value, _ = cache.Load("key", time.Second, func() (value interface{}, err error) {
6157 return 666, nil
6258 })
6359 }
6460
6561 fmt.Println(value) // 666
6662
63+ // You can use WithLRU to specify the type of cache to lru.
64+ // Also, try WithLFU if you want to use lfu to evict data.
65+ cache = cachego.NewCache(cachego.WithLRU(100))
66+ cache = cachego.NewCache(cachego.WithLFU(100))
67+
67682. ttl:
6869
6970 cache := cachego.NewCache()
@@ -467,4 +468,4 @@ Package cachego provides an easy way to use foundation for your caching operatio
467468package cachego // import "github.com/FishGoddess/cachego"
468469
469470// Version is the version string representation of cachego.
470- const Version = "v0.4.6 "
471+ const Version = "v0.4.7 "
0 commit comments