mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
app/abi/manager.go: pass context to cache.
This commit is contained in:
parent
5a5e4bfd2e
commit
1d5e28a38f
1 changed files with 10 additions and 2 deletions
|
|
@ -27,14 +27,16 @@ func NewAbiManager(cache *cache.Cache, api *eos.API) *AbiManager {
|
|||
|
||||
// Set or update an ABI in the cache.
|
||||
func (mgr *AbiManager) SetAbi(account eos.AccountName, abi *eos.ABI) error {
|
||||
return mgr.cache.Set(string(account), *abi, time.Hour)
|
||||
ctx, cancel := context.WithTimeout(mgr.ctx, time.Millisecond*500)
|
||||
defer cancel()
|
||||
return mgr.cache.Set(ctx, string(account), *abi, time.Hour)
|
||||
}
|
||||
|
||||
// Get an ABI from the cache, on cache miss it is fetched from the
|
||||
// API, gets cached and then returned to the user
|
||||
func (mgr *AbiManager) GetAbi(account eos.AccountName) (*eos.ABI, error) {
|
||||
var abi eos.ABI
|
||||
if err := mgr.cache.Get(string(account), &abi); err != nil {
|
||||
if err := mgr.cacheGet(account, &abi); err != nil {
|
||||
ctx, cancel := context.WithTimeout(mgr.ctx, time.Second)
|
||||
defer cancel()
|
||||
resp, err := mgr.api.GetABI(ctx, account)
|
||||
|
|
@ -50,3 +52,9 @@ func (mgr *AbiManager) GetAbi(account eos.AccountName) (*eos.ABI, error) {
|
|||
}
|
||||
return &abi, nil
|
||||
}
|
||||
|
||||
func (mgr *AbiManager) cacheGet(account eos.AccountName, value any) error {
|
||||
ctx, cancel := context.WithTimeout(mgr.ctx, time.Millisecond*500)
|
||||
defer cancel()
|
||||
return mgr.cache.Get(ctx, string(account), value)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue