Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .gitattributes

This file was deleted.

7 changes: 5 additions & 2 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## ✒ 未来版本的新特性 (Features in future versions)

### v1.0.0

* [x] 稳定的 API

### v0.6.x

* [ ] 梳理代码,优化代码风格,精简部分代码和注释
* [ ] 完善监控上报器,提供更多缓存信息查询的方法
* [x] 梳理代码,优化代码风格,精简部分代码和注释

### v0.5.x

Expand Down
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## ✒ 历史版本的特性介绍 (Features in old versions)

### v1.0.0

> 此版本发布于 2025-03-15

* 稳定的 API 版本
* 调整快速时钟的代码,更改包名为 fastclock

### v0.6.1

> 此版本发布于 2024-01-18
Expand Down
9 changes: 3 additions & 6 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* Sentinel cleanup supports, cleaning up at fixed duration
* Singleflight supports, which can decrease the times of cache penetration
* Timer task supports, which is convenient to load data to cache
* Report supports, providing several reporting points.
* Report supports, providing several reporting points
* Fast clock supports, fetching current time in nanoseconds

_Check [HISTORY.md](./HISTORY.md) and [FUTURE.md](./FUTURE.md) to get more information._

Expand Down Expand Up @@ -143,11 +144,7 @@ BenchmarkGoCacheSet-12 4921483 249.0 ns/op

> Notice: Ecache only has lru mode, including v1 and v2; Freecache has 256 shardings, and we can't reset to 1.

> Benchmarks: [_examples/performance_test.go](./_examples/performance_test.go)

As you can see, cachego has a higher performance with sharding, but sharding has one-more-time positioning
operation, so if the locking cost is less than the cost of positioning, this sharding is dragging. However, it has
better performance in most time.
> Benchmarks: [_examples/performance_test.go](./_examples/performance_test.go).

### 👥 Contributors

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* 自带 singleflight 机制,减少缓存穿透的伤害
* 自带定时任务封装,方便热数据定时加载到缓存
* 支持上报缓存状况,可自定义多个缓存上报点
* 自带快速时钟,支持纳秒级获取时间

_历史版本的特性请查看 [HISTORY.md](./HISTORY.md)。未来版本的新特性和计划请查看 [FUTURE.md](./FUTURE.md)。_

Expand Down Expand Up @@ -142,10 +143,7 @@ BenchmarkGoCacheSet-12 4921483 249.0 ns/op

> 注:Ecache 只有 LRU 模式,v1 和 v2 两个版本;Freecache 默认是 256 分片,无法调节为 1 个分片进行对比测试。

> 测试文件:[_examples/performance_test.go](./_examples/performance_test.go)

可以看出,使用分片机制后的读写性能非常高,但是分片会多一次哈希定位的操作,如果加锁的消耗小于定位的消耗,那分片就不占优势。
不过在绝大多数的情况下,分片机制带来的性能提升都是巨大的,尤其是对写操作较多的 lru 和 lfu 实现。
> 测试文件:[_examples/performance_test.go](./_examples/performance_test.go)。

### 👥 贡献者

Expand Down
2 changes: 1 addition & 1 deletion _examples/basic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 5 additions & 9 deletions _examples/clock.go → _examples/fast_clock.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,21 +20,17 @@ import (
"time"

"github.com/FishGoddess/cachego"
"github.com/FishGoddess/cachego/pkg/clock"
"github.com/FishGoddess/cachego/pkg/fastclock"
)

func main() {
// Create a fast clock and get current time in nanosecond by Now.
c := clock.New()
c.Now()

// Fast clock may return an "incorrect" time compared with time.Now.
// The gap will be smaller than about 100 ms.
for i := 0; i < 10; i++ {
time.Sleep(time.Duration(rand.Int63n(int64(time.Second))))

timeNow := time.Now().UnixNano()
clockNow := c.Now()
clockNow := fastclock.NowNanos()

fmt.Println(timeNow)
fmt.Println(clockNow)
Expand All @@ -43,8 +39,8 @@ func main() {
}

// You can specify the fast clock to cache by WithNow.
// All getting current time operations in this cache will use fast clock.
cache := cachego.NewCache(cachego.WithNow(clock.New().Now))
// All time used in this cache will be got from fast clock.
cache := cachego.NewCache(cachego.WithNow(fastclock.NowNanos))
cache.Set("key", 666, 100*time.Millisecond)

value, ok := cache.Get("key")
Expand Down
2 changes: 1 addition & 1 deletion _examples/gc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/lfu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/load.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/lru.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/performance_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/report.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/sharding.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/task.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion _examples/ttl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cache_type.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cache_type_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 FishGoddess. All Rights Reserved.
// Copyright 2025 FishGoddess. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading
Loading