1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-18 04:40:03 +02:00

convert abi_cache into a proper package.

This commit is contained in:
Henrik Hautakoski 2022-03-11 11:28:16 +01:00
parent 97a3f0e2f3
commit 8df93439c3
6 changed files with 1 additions and 580 deletions

42
abi_cache/cache.go Normal file
View file

@ -0,0 +1,42 @@
package abi_cache
import (
"time"
"context"
redis_cache "github.com/go-redis/cache/v8"
eos "github.com/eoscanada/eos-go"
)
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 (this *Cache) Get(account string) (*eos.ABI, error) {
var v eos.ABI
err := this.c.Get(this.ctx, this.key(account), &v);
return &v, err
}
func (this *Cache) Set(account string, abi *eos.ABI, ttl time.Duration) error {
return this.c.Set(&redis_cache.Item{
Ctx: this.ctx,
Key: this.key(account),
Value: *abi,
TTL: ttl,
})
}
func (this *Cache) key(account string) (string) {
return this.prefix + "." + account
}