Skip to content

Commit 0d28fc6

Browse files
committed
祝妈妈、老婆妇女节快乐!
1 parent df529d5 commit 0d28fc6

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## ✒ 历史版本的特性介绍 (Features in old versions)
22

3+
### v0.4.7
4+
5+
> 此版本发布于 2023-03-08
6+
7+
* 默认开启 10 分钟的 GC(因为从线上使用情况来看开启的概率远远大于不开启)
8+
* 默认限制最多缓存 10w 个键值对,如果需要不限制,可以使用 WithMaxEntries 指定为 0
9+
* 完善文档和使用案例,特别是强调了 GC 和单飞的使用
10+
* 祝我的妈妈,我的老婆女神节、妇女节都快乐!
11+
312
### v0.4.6
413

514
> 此版本发布于 2023-03-01

README.en.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,10 @@ import (
4747

4848
func main() {
4949
// Use NewCache function to create a cache.
50-
// You can use WithLRU to specify the type of cache to lru.
51-
// Also, try WithLFU if you want to use lfu to evict data.
52-
cache := cachego.NewCache(cachego.WithLRU(100))
53-
cache = cachego.NewCache(cachego.WithLFU(100))
54-
5550
// By default, it creates a standard cache which evicts entries randomly.
5651
// Use WithShardings to shard cache to several parts for higher performance.
57-
cache = cachego.NewCache(cachego.WithShardings(64))
58-
cache = cachego.NewCache()
52+
// Use WithGC to clean expired entries every 10 minutes.
53+
cache := cachego.NewCache(cachego.WithGC(10*time.Minute), cachego.WithShardings(64))
5954

6055
// Set an entry to cache with ttl.
6156
cache.Set("key", 123, time.Second)
@@ -86,12 +81,18 @@ func main() {
8681
value, ok = cache.Get("key")
8782
if !ok {
8883
// Loaded entry will be set to cache and returned.
84+
// By default, it will use singleflight.
8985
value, _ = cache.Load("key", time.Second, func() (value interface{}, err error) {
9086
return 666, nil
9187
})
9288
}
9389

9490
fmt.Println(value) // 666
91+
92+
// You can use WithLRU to specify the type of cache to lru.
93+
// Also, try WithLFU if you want to use lfu to evict data.
94+
cache = cachego.NewCache(cachego.WithLRU(100))
95+
cache = cachego.NewCache(cachego.WithLFU(100))
9596
}
9697
```
9798

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
**cachego** 是一个拥有分片机制的轻量级内存缓存库,API 友好,支持多种数据淘汰机制,可以应用于所有的 [GoLang](https://golang.org) 应用程序中。
99

10-
> 目前 v0.3.x 版本已经在多个线上服务中运行稳定,服务日常请求过万 qps,最高抵御过 96w/s qps 的冲击,欢迎使用!👏🏻
10+
> 目前 v0.3.x 版本已经在多个线上服务中运行稳定,服务日常请求过万 qps,瞬时最高抵御过 96w/s qps 的冲击,欢迎使用!👏🏻
1111
1212
[Read me in English](./README.en.md).
1313

@@ -46,15 +46,10 @@ import (
4646

4747
func main() {
4848
// Use NewCache function to create a cache.
49-
// You can use WithLRU to specify the type of cache to lru.
50-
// Also, try WithLFU if you want to use lfu to evict data.
51-
cache := cachego.NewCache(cachego.WithLRU(100))
52-
cache = cachego.NewCache(cachego.WithLFU(100))
53-
5449
// By default, it creates a standard cache which evicts entries randomly.
5550
// Use WithShardings to shard cache to several parts for higher performance.
56-
cache = cachego.NewCache(cachego.WithShardings(64))
57-
cache = cachego.NewCache()
51+
// Use WithGC to clean expired entries every 10 minutes.
52+
cache := cachego.NewCache(cachego.WithGC(10*time.Minute), cachego.WithShardings(64))
5853

5954
// Set an entry to cache with ttl.
6055
cache.Set("key", 123, time.Second)
@@ -85,12 +80,18 @@ func main() {
8580
value, ok = cache.Get("key")
8681
if !ok {
8782
// Loaded entry will be set to cache and returned.
83+
// By default, it will use singleflight.
8884
value, _ = cache.Load("key", time.Second, func() (value interface{}, err error) {
8985
return 666, nil
9086
})
9187
}
9288

9389
fmt.Println(value) // 666
90+
91+
// You can use WithLRU to specify the type of cache to lru.
92+
// Also, try WithLFU if you want to use lfu to evict data.
93+
cache = cachego.NewCache(cachego.WithLRU(100))
94+
cache = cachego.NewCache(cachego.WithLFU(100))
9495
}
9596
```
9697

_examples/basic.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ import (
2323

2424
func main() {
2525
// Use NewCache function to create a cache.
26-
// You can use WithLRU to specify the type of cache to lru.
27-
// Also, try WithLFU if you want to use lfu to evict data.
28-
cache := cachego.NewCache(cachego.WithLRU(100))
29-
cache = cachego.NewCache(cachego.WithLFU(100))
30-
3126
// By default, it creates a standard cache which evicts entries randomly.
3227
// Use WithShardings to shard cache to several parts for higher performance.
33-
cache = cachego.NewCache(cachego.WithShardings(64))
34-
cache = cachego.NewCache()
28+
// Use WithGC to clean expired entries every 10 minutes.
29+
cache := cachego.NewCache(cachego.WithGC(10*time.Minute), cachego.WithShardings(64))
3530

3631
// Set an entry to cache with ttl.
3732
cache.Set("key", 123, time.Second)
@@ -62,10 +57,16 @@ func main() {
6257
value, ok = cache.Get("key")
6358
if !ok {
6459
// Loaded entry will be set to cache and returned.
60+
// By default, it will use singleflight.
6561
value, _ = cache.Load("key", time.Second, func() (value interface{}, err error) {
6662
return 666, nil
6763
})
6864
}
6965

7066
fmt.Println(value) // 666
67+
68+
// You can use WithLRU to specify the type of cache to lru.
69+
// Also, try WithLFU if you want to use lfu to evict data.
70+
cache = cachego.NewCache(cachego.WithLRU(100))
71+
cache = cachego.NewCache(cachego.WithLFU(100))
7172
}

config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ func newDefaultConfig() *config {
4444
cacheType: standard,
4545
shardings: 0,
4646
singleflight: true,
47-
gcDuration: 0,
47+
gcDuration: 10 * time.Minute,
4848
maxScans: 10000,
49-
maxEntries: 0,
49+
maxEntries: 100000,
5050
now: now,
5151
hash: hash,
5252
recordMissed: true,

doc.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ Package cachego provides an easy way to use foundation for your caching operatio
1818
1. 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+
6768
2. ttl:
6869
6970
cache := cachego.NewCache()
@@ -467,4 +468,4 @@ Package cachego provides an easy way to use foundation for your caching operatio
467468
package 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

Comments
 (0)