github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/utils/signers/gsignercache/global_cache.go (about)

     1  package gsignercache
     2  
     3  import (
     4  	lru "github.com/hashicorp/golang-lru"
     5  
     6  	"github.com/unicornultrafoundation/go-u2u/common"
     7  	"github.com/unicornultrafoundation/go-u2u/core/types"
     8  )
     9  
    10  var (
    11  	globalCache, _ = lru.New(40000)
    12  )
    13  
    14  type WlruCache struct {
    15  	Cache *lru.Cache
    16  }
    17  
    18  func (w *WlruCache) Add(txid common.Hash, c types.CachedSender) {
    19  	w.Cache.Add(txid, c)
    20  }
    21  
    22  func (w *WlruCache) Get(txid common.Hash) *types.CachedSender {
    23  	ic, ok := w.Cache.Get(txid)
    24  	if !ok {
    25  		return nil
    26  	}
    27  	c := ic.(types.CachedSender)
    28  	return &c
    29  }
    30  
    31  func Wrap(signer types.Signer) types.Signer {
    32  	return types.WrapWithCachedSigner(signer, &WlruCache{globalCache})
    33  }