1b4e881d74
* WIP store rewrite * Fix memory store tests * Store hard expiry times rather than duration! * Clarify memory test * Add limit to store interface * Implement suffix option * Don't return nils from noop store * Fix syncmap * Start fixing store service * wip service and cache * Use _ for special characters in cockroachdb namespace * Improve cockroach namespace comment * Use service name as default store namespace * Fixes * Implement Store Scope * Start fixing etcd * implement read and write with expiry and prefix * Fix etcd tests * Fix cockroach store * Fix cloudflare interface * Fix certmagic / cloudflare store * comment lint * cache isn't implemented yet * Only prepare DB staements once Co-authored-by: Ben Toogood <ben@micro.mu> Co-authored-by: ben-toogood <bentoogood@gmail.com>
40 lines
720 B
Go
40 lines
720 B
Go
package cache
|
|
|
|
import (
|
|
"github.com/micro/go-micro/v2/store"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Cache implements a cache in front of a micro Store
|
|
type Cache struct {
|
|
options store.Options
|
|
store.Store
|
|
|
|
stores []store.Store
|
|
}
|
|
|
|
// NewStore returns new cache
|
|
func NewStore(opts ...store.Option) store.Store {
|
|
s := &Cache{
|
|
options: store.Options{},
|
|
stores: []store.Store{},
|
|
}
|
|
for _, o := range opts {
|
|
o(&s.options)
|
|
}
|
|
return s
|
|
}
|
|
|
|
// Init initialises a new cache
|
|
func (c *Cache) Init(opts ...store.Option) error {
|
|
for _, o := range opts {
|
|
o(&c.options)
|
|
}
|
|
for _, s := range c.stores {
|
|
if err := s.Init(); err != nil {
|
|
return errors.Wrapf(err, "Store %s failed to Init()", s.String())
|
|
}
|
|
}
|
|
return nil
|
|
}
|