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