Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultTTL = 30 * time.Minute
DefaultTTL specifies default TTL
View Source
var ErrNotFound = errors.New("not found")
ErrNotFound defines not found error
View Source
var KeepTTL = time.Duration(-1)
KeepTTL specifies to keep value
View Source
var NowFunc = time.Now
NowFunc allows to override default time
Functions ¶
func IsNotFoundError ¶
IsNotFoundError returns true, if error is NotFound
Types ¶
type Config ¶
type Config struct {
// Provider specifies the cache provider: redis|memory
Provider string `json:"provider" yaml:"provider"`
Redis *RedisConfig `json:"redis" yaml:"redis"`
}
Config specifies configuration of the cache.
type Provider ¶
type Provider interface {
// Set data
Set(ctx context.Context, key string, v any, ttl time.Duration) error
// Get data
Get(ctx context.Context, key string, v any) error
// Delete data
Delete(ctx context.Context, key string) error
// CleanExpired data
CleanExpired(ctx context.Context)
// Close closes the client, releasing any open resources.
// It is rare to Close a Client, as the Client is meant to be long-lived and shared between many goroutines.
Close() error
// Keys returns list of keys.
// This method should be used mostly for testing, as in prod many keys maybe returned
Keys(ctx context.Context, pattern string) ([]string, error)
// IsLocal returns true, if cache is local
IsLocal() bool
// Publish publishes message to channel
Publish(ctx context.Context, channel, message string) error
// Subscribe subscribes to channel
Subscribe(ctx context.Context, channel string) Subscription
}
Provider defines cache interface
func NewMemoryProvider ¶
NewMemoryProvider returns memory cache
func NewProxyProvider ¶
NewProxyProvider returns proxy provider
func NewRedisProvider ¶
func NewRedisProvider(cfg RedisConfig, prefix string) (Provider, error)
NewRedisProvider returns Redis cache
type RedisConfig ¶
type RedisConfig struct {
Server string `json:"server,omitempty" yaml:"server,omitempty"`
TTL time.Duration `json:"ttl,omitempty" yaml:"ttl,omitempty"`
// ClientTLS describes the TLS certs used to connect to the cluster
ClientTLS *gserver.TLSInfo `json:"client_tls,omitempty" yaml:"client_tls,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
}
RedisConfig specifies configuration of the redis.
Click to show internal directories.
Click to hide internal directories.