Skip to content

Commit

Permalink
Merge pull request #35 from mgtv-tech/perf_statslogger
Browse files Browse the repository at this point in the history
update dependencies and docs.
  • Loading branch information
daoshenzzg authored Oct 9, 2024
2 parents 4c9c985 + 47de37b commit d5a844a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 107 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Translate to: [简体中文](README_zh.md)

# Introduction
# Overview
[jetcache-go](https://github.com/mgtv-tech/jetcache-go) is a general-purpose cache access framework based on
[go-redis/cache](https://github.com/go-redis/cache). It implements the core features of the Java version of
[JetCache](https://github.com/alibaba/jetcache), including:
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Translations: [English](README.md) | [简体中文](README_zh.md)

# 介绍
# 简介
[jetcache-go](https://github.com/mgtv-tech/jetcache-go)是基于[go-redis/cache](https://github.com/go-redis/cache)拓展的通用缓存访问框架。
实现了类似Java版[JetCache](https://github.com/alibaba/jetcache)的核心功能,包括:

Expand Down
8 changes: 2 additions & 6 deletions cachegeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ func NewT[K constraints.Ordered, V any](cache Cache) *T[K, V] {
// Set sets the value `v` associated with the given `key` and `id` in the cache.
// The expiration time of the cached value is determined by the cache configuration.
func (w *T[K, V]) Set(ctx context.Context, key string, id K, v V) error {
c := w.Cache.(*jetCache)

combKey := fmt.Sprintf("%s:%v", key, id)
return c.Set(ctx, combKey, Value(v))
return w.Cache.Set(ctx, combKey, Value(v))
}

// Get retrieves the value associated with the given `key` and `id`.
Expand All @@ -40,11 +38,9 @@ func (w *T[K, V]) Set(ctx context.Context, key string, id K, v V) error {
// A `Once` mechanism is employed to ensure only one fetch is performed for a given `key` and `id`
// combination, even under concurrent access.
func (w *T[K, V]) Get(ctx context.Context, key string, id K, fn func(context.Context, K) (V, error)) (V, error) {
c := w.Cache.(*jetCache)

var varT V
combKey := fmt.Sprintf("%s:%v", key, id)
err := c.Once(ctx, combKey, Value(&varT), Do(func(ctx context.Context) (any, error) {
err := w.Once(ctx, combKey, Value(&varT), Do(func(ctx context.Context) (any, error) {
return fn(ctx, id)
}))

Expand Down
40 changes: 20 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ module github.com/mgtv-tech/jetcache-go
go 1.20

require (
github.com/alicebob/miniredis/v2 v2.30.5
github.com/bytedance/sonic v1.11.2
github.com/coocood/freecache v1.2.3
github.com/dgraph-io/ristretto v0.1.1
github.com/klauspost/compress v1.16.7
github.com/alicebob/miniredis/v2 v2.33.0
github.com/bytedance/sonic v1.12.3
github.com/coocood/freecache v1.2.4
github.com/dgraph-io/ristretto v1.0.0
github.com/klauspost/compress v1.17.9
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
github.com/onsi/gomega v1.34.1
github.com/redis/go-redis/v9 v9.6.1
github.com/stretchr/testify v1.8.2
github.com/vmihailenco/msgpack/v5 v5.3.5
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/sync v0.7.0
github.com/stretchr/testify v1.9.0
github.com/vmihailenco/msgpack/v5 v5.4.1
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e
golang.org/x/sync v0.8.0
)

require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.17.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d5a844a

Please sign in to comment.