micro/cache/cache.go

35 lines
696 B
Go
Raw Normal View History

2020-07-08 13:08:59 +03:00
// Package cache is a caching interface
package cache
import "context"
// Cache is an interface for caching
2020-07-08 13:08:59 +03:00
type Cache interface {
// Initialise options
Init(...Option) error
// Get a value
Get(ctx context.Context, key string) (interface{}, error)
2020-07-08 13:08:59 +03:00
// Set a value
Set(ctx context.Context, key string, val interface{}) error
2020-07-08 13:08:59 +03:00
// Delete a value
Delete(ctx context.Context, key string) error
2020-07-08 13:08:59 +03:00
// Name of the implementation
String() string
}
// Options struct
type Options struct {
Nodes []string
Context context.Context
}
2020-07-08 16:53:38 +03:00
// Option func
2020-07-08 16:53:38 +03:00
type Option func(o *Options)
// Nodes sets the nodes for the cache
func Nodes(v ...string) Option {
return func(o *Options) {
o.Nodes = v
}
}