diff --git a/FUTURE.md b/FUTURE.md index 9c19e96..ac8a047 100644 --- a/FUTURE.md +++ b/FUTURE.md @@ -1,5 +1,9 @@ ## ✒ 未来版本的新特性 (Features in future versions) +### v0.5.x + +* [ ] 提供一个清空并设置全量值的方法,方便定时数据的全量替换 + ### v0.4.x * [x] 设计 Cache 接口,Get 方法用 bool 判断,单个锁结构 @@ -21,7 +25,6 @@ * [ ] ~~增加对不存在的数据做防穿透的机制~~ 经过实践,这个更适合业务方自己处理,所以这边就先去掉了 * [ ] 完善监控上报器,提供更多缓存信息查询的方法 -* [ ] 提供一个清空并设置全量值的方法,方便定时数据的全量替换 ### v0.3.x diff --git a/HISTORY.md b/HISTORY.md index 130cb29..743a05d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,11 @@ ## ✒ 历史版本的特性介绍 (Features in old versions) +### v0.4.12 + +> 此版本发布于 2023-06-12 + +* 给 Reporter 增加缓存 gc 运行间隔方法,主要用于监控不同缓存的 gc 运行间隔配置情况 + ### v0.4.11 > 此版本发布于 2023-05-10 diff --git a/README.en.md b/README.en.md index f937341..34cb181 100644 --- a/README.en.md +++ b/README.en.md @@ -8,7 +8,7 @@ **cachego** is an api friendly memory-based cache for [GoLang](https://golang.org) applications. > It has been used by many services in production, all services are running stable, and the highest qps in services is -> 96w/s by using v0.3.x, so just use it if you want! 👏🏻 +> 96w/s, so just use it if you want! 👏🏻 [阅读中文版的 Read me](./README.md). diff --git a/README.md b/README.md index f25a21d..79c1bd3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ **cachego** 是一个拥有分片机制的轻量级内存缓存库,API 友好,支持多种数据淘汰机制,可以应用于所有的 [GoLang](https://golang.org) 应用程序中。 -> 目前已经在多个线上服务中运行稳定,服务日常请求过万 qps,v0.3.x 版本最高抵御过 96w/s qps 的冲击,欢迎使用!👏🏻 +> 目前已经在多个线上服务中运行稳定,服务日常请求过万 qps,最高抵御过 96w/s qps 的冲击,欢迎使用!👏🏻 [Read me in English](./README.en.md). diff --git a/doc.go b/doc.go index 4bf1c2e..3210569 100644 --- a/doc.go +++ b/doc.go @@ -480,4 +480,4 @@ Package cachego provides an easy way to use foundation for your caching operatio package cachego // import "github.com/FishGoddess/cachego" // Version is the version string representation of cachego. -const Version = "v0.4.11" +const Version = "v0.4.12" diff --git a/report.go b/report.go index 052e520..31915c3 100644 --- a/report.go +++ b/report.go @@ -65,6 +65,18 @@ func (r *Reporter) CacheShardings() int { return r.conf.shardings } +// CacheGC returns the gc duration of cache. +// You can use WithGC to set cache's gc duration. +// Zero duration means cache disables gc. +func (r *Reporter) CacheGC() time.Duration { + return r.conf.gcDuration +} + +// CacheSize returns the size of cache. +func (r *Reporter) CacheSize() int { + return r.cache.Size() +} + // CountMissed returns the missed count. func (r *Reporter) CountMissed() uint64 { return atomic.LoadUint64(&r.missedCount) @@ -85,11 +97,6 @@ func (r *Reporter) CountLoad() uint64 { return atomic.LoadUint64(&r.loadCount) } -// CacheSize returns the size of cache. -func (r *Reporter) CacheSize() int { - return r.cache.Size() -} - // MissedRate returns the missed rate. func (r *Reporter) MissedRate() float64 { hit := r.CountHit() diff --git a/report_test.go b/report_test.go index 66873e2..6151d4c 100644 --- a/report_test.go +++ b/report_test.go @@ -21,9 +21,10 @@ import ( ) const ( - testCacheName = "test" - testCacheType = lru - testCacheShardings = 16 + testCacheName = "test" + testCacheType = lru + testCacheShardings = 16 + testCacheGCDuration = 10 * time.Minute ) func newTestReportableCache() (*reportableCache, *Reporter) { @@ -31,6 +32,7 @@ func newTestReportableCache() (*reportableCache, *Reporter) { conf.cacheName = testCacheName conf.cacheType = testCacheType conf.shardings = testCacheShardings + conf.gcDuration = testCacheGCDuration conf.maxEntries = maxTestEntries cache, reporter := report(conf, newStandardCache(conf)) @@ -241,6 +243,18 @@ func TestReporterCacheShardings(t *testing.T) { } } +// go test -v -cover -run=^TestReporterCacheGC$ +func TestReporterCacheGC(t *testing.T) { + _, reporter := newTestReportableCache() + if reporter.CacheGC() != reporter.conf.gcDuration { + t.Errorf("CacheGC %d is wrong compared with conf", reporter.CacheGC()) + } + + if reporter.CacheGC() != testCacheGCDuration { + t.Errorf("CacheGC %d is wrong", reporter.CacheGC()) + } +} + // go test -v -cover -run=^TestReporterCacheSize$ func TestReporterCacheSize(t *testing.T) { cache, reporter := newTestReportableCache()