Streams tenancy (#91)

* fixup streams stuff

* use cache instead of pg in streams

* hash out issuer streams test

* fix compile error
This commit is contained in:
Asim Aslam
2021-05-01 22:34:35 +01:00
committed by GitHub
parent 500acefe47
commit b8877f8312
8 changed files with 87 additions and 82 deletions

55
pkg/cache/cache.go vendored
View File

@@ -8,8 +8,30 @@ import (
"github.com/micro/micro/v3/service/store"
)
func Get(key string, val interface{}) error {
recs, err := store.Read(key, store.ReadLimit(1))
type Cache interface {
Get(key string, val interface{}) error
Put(key string, val interface{}, expires time.Time) error
Delete(key string) error
}
type cache struct {
Store store.Store
}
var (
DefaultCache = New(nil)
)
func New(st store.Store) Cache {
return &cache{st}
}
func (c *cache) Get(key string, val interface{}) error {
if c.Store == nil {
c.Store = store.DefaultStore
}
recs, err := c.Store.Read(key, store.ReadLimit(1))
if err != nil {
return err
}
@@ -22,19 +44,40 @@ func Get(key string, val interface{}) error {
return nil
}
func Put(key string, val interface{}, expires time.Time) error {
func (c *cache) Put(key string, val interface{}, expires time.Time) error {
if c.Store == nil {
c.Store = store.DefaultStore
}
b, err := json.Marshal(val)
if err != nil {
return err
}
expiry := expires.Sub(time.Now())
return store.Write(&store.Record{
if expiry < time.Duration(0) {
expiry = time.Duration(0)
}
return c.Store.Write(&store.Record{
Key: key,
Value: b,
Expiry: expiry,
})
}
func Delete(key string) error {
return store.Delete(key)
func (c *cache) Delete(key string) error {
if c.Store == nil {
c.Store = store.DefaultStore
}
return c.Store.Delete(key)
}
func Get(key string, val interface{}) error {
return DefaultCache.Get(key, val)
}
func Put(key string, val interface{}, expires time.Time) error {
return DefaultCache.Put(key, val, expires)
}
func Delete(key string) error {
return DefaultCache.Delete(key)
}