Skip to content

Commit

Permalink
fix: change lib
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhongtao committed Oct 12, 2023
1 parent ab989fa commit 0c0dbec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions blockchain/chain/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"time"

"github.com/0xcregis/easynode/blockchain"
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/patrickmn/go-cache"
"github.com/tidwall/gjson"
)

type Btc struct {
lru *expirable.LRU[string, string]
lru *cache.Cache
}

func (e *Btc) GetToken721(host string, key string, contractAddress string, userAddress string) (map[string]interface{}, error) {
Expand Down Expand Up @@ -49,9 +49,9 @@ func (e *Btc) UnSubscribe(host string, token string) (string, error) {
}

func NewChainClient() blockchain.ChainConn {
cache := expirable.NewLRU[string, string](100, nil, time.Minute*5)
c := cache.New(5*time.Minute, time.Minute*10)
return &Btc{
lru: cache,
lru: c,
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ func (e *Btc) SendRequestToChain(host string, token string, query string) (strin
keyCache = hex.EncodeToString(hash[:])
valueCache, ok := e.lru.Get(keyCache)
if ok {
return valueCache, nil
return valueCache.(string), nil
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func (e *Btc) SendRequestToChain(host string, token string, query string) (strin

value := string(body)
if e.lru != nil && cacheOK {
e.lru.Add(keyCache, value)
e.lru.Set(keyCache, value, cache.DefaultExpiration)
}
return value, nil
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/ipfs/go-cid v0.4.1
github.com/multiformats/go-multihash v0.2.1
github.com/multiformats/go-varint v0.0.7
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/redis/go-redis/v9 v9.0.4
github.com/segmentio/kafka-go v0.4.39
github.com/shengdoushi/base58 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4=
github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU=
github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/golang-lru/v2 v2.0.6 h1:3xi/Cafd1NaoEnS/yDssIiuVeDVywU0QdFGl3aQaQHM=
github.com/hashicorp/golang-lru/v2 v2.0.6/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
Expand Down Expand Up @@ -1333,6 +1331,8 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/name v1.0.0/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
github.com/pascaldekloe/name v1.0.1/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/paulmach/orb v0.9.0 h1:MwA1DqOKtvCgm7u9RZ/pnYejTeDJPnr0+0oFajBbJqk=
github.com/paulmach/orb v0.9.0/go.mod h1:SudmOk85SXtmXAB3sLGyJ6tZy/8pdfrV0o6ef98Xc30=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
Expand Down

0 comments on commit 0c0dbec

Please sign in to comment.