mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-18 04:40:03 +02:00
move internal/abi_cache to abi
This commit is contained in:
parent
c05b789269
commit
92c605c7fa
3 changed files with 7 additions and 8 deletions
|
|
@ -1,42 +0,0 @@
|
|||
package abi_cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
eos "github.com/eoscanada/eos-go"
|
||||
redis_cache "github.com/go-redis/cache/v8"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
c *redis_cache.Cache
|
||||
ctx context.Context
|
||||
prefix string
|
||||
}
|
||||
|
||||
func New(prefix string, options *redis_cache.Options) *Cache {
|
||||
return &Cache{
|
||||
c: redis_cache.New(options),
|
||||
ctx: context.Background(),
|
||||
prefix: prefix,
|
||||
}
|
||||
}
|
||||
|
||||
func (cache *Cache) Get(account string) (*eos.ABI, error) {
|
||||
var v eos.ABI
|
||||
err := cache.c.Get(cache.ctx, cache.key(account), &v)
|
||||
return &v, err
|
||||
}
|
||||
|
||||
func (cache *Cache) Set(account string, abi *eos.ABI, ttl time.Duration) error {
|
||||
return cache.c.Set(&redis_cache.Item{
|
||||
Ctx: cache.ctx,
|
||||
Key: cache.key(account),
|
||||
Value: *abi,
|
||||
TTL: ttl,
|
||||
})
|
||||
}
|
||||
|
||||
func (cache *Cache) key(account string) string {
|
||||
return cache.prefix + "." + account
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue