From 5698e36b0560145fcaf6609c270bce0e4486ce8b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 15 Jun 2024 21:05:32 +0800 Subject: [PATCH] 1 --- server/marketserver/cache/cachemgr.go | 22 +++++++++++++++++----- server/marketserver/common/types.go | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/marketserver/cache/cachemgr.go b/server/marketserver/cache/cachemgr.go index eaf848b4..a511917c 100644 --- a/server/marketserver/cache/cachemgr.go +++ b/server/marketserver/cache/cachemgr.go @@ -1,7 +1,9 @@ package cache import ( + "f5" "sync" + "fmt" "main/common" ) @@ -18,12 +20,22 @@ func (this *cacheMgr) UnInit() { } func (this *cacheMgr) GetNfts(nfts []*common.NftDto) { - /* for _, val := range nfts { - - }*/ + this.internalGetNft(val) + } } -func (this *cacheMgr) internalGetNft(netId int32, contractAddress string, tokenId string) *nft { - return nil +func (this *cacheMgr) internalGetNft(dto *common.NftDto) { + key := fmt.Sprintf("%d_%s_%s", dto.NetId, dto.ContractAddress, dto.TokenId) + if p, ok := this.nftHash.Load(key); ok { + dto.NftCache = p.(*nft) + } else { + l := f5.AllocLock(key) + defer f5.ReleaseLock(l) + if p, ok := this.nftHash.Load(key); ok { + dto.NftCache = p.(*nft) + } else { + + } + } } diff --git a/server/marketserver/common/types.go b/server/marketserver/common/types.go index 44f91589..95a92d87 100644 --- a/server/marketserver/common/types.go +++ b/server/marketserver/common/types.go @@ -43,7 +43,7 @@ type StreamPagination struct { } type NftCache interface { - + GetRawData() string } type NftDto struct {