Documentation ¶
Overview ¶
Package cache implements the types.Cache interface for storing and retrieving key/value pairs from a range of storage strategies.
Index ¶
- Constants
- Variables
- func Descriptions() string
- func New(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
- func NewDynamoDB(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
- func NewMemcached(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
- func NewMemory(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
- func SanitiseConfig(conf Config) (interface{}, error)
- type AmazonAWSCredentialsConfig
- type Config
- type DynamoDB
- type DynamoDBConfig
- type Memcached
- type MemcachedConfig
- type Memory
- type MemoryConfig
- type TypeSpec
Constants ¶
const ( TypeDynamoDB = "dynamodb" TypeMemcached = "memcached" TypeMemory = "memory" )
String constants representing each cache type.
Variables ¶
var Constructors = map[string]TypeSpec{}
Constructors is a map of all cache types with their specs.
Functions ¶
func Descriptions ¶
func Descriptions() string
Descriptions returns a formatted string of descriptions for each type.
func New ¶
func New( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (types.Cache, error)
New creates a cache type based on an cache configuration.
func NewDynamoDB ¶ added in v0.28.0
func NewDynamoDB(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
NewDynamoDB creates a new DynamoDB cache type.
func NewMemcached ¶
func NewMemcached( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (types.Cache, error)
NewMemcached returns a Memcached processor.
func NewMemory ¶
func NewMemory(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
NewMemory creates a new Memory cache type.
func SanitiseConfig ¶ added in v0.16.2
SanitiseConfig creates a sanitised version of a config.
Types ¶
type AmazonAWSCredentialsConfig ¶ added in v0.28.0
type AmazonAWSCredentialsConfig struct { ID string `json:"id" yaml:"id"` Secret string `json:"secret" yaml:"secret"` Token string `json:"token" yaml:"token"` Role string `json:"role" yaml:"role"` }
AmazonAWSCredentialsConfig contains configuration params for AWS credentials.
type Config ¶
type Config struct { Type string `json:"type" yaml:"type"` DynamoDB DynamoDBConfig `json:"dynamodb" yaml:"dynamodb"` Memcached MemcachedConfig `json:"memcached" yaml:"memcached"` Memory MemoryConfig `json:"memory" yaml:"memory"` }
Config is the all encompassing configuration struct for all cache types.
func NewConfig ¶
func NewConfig() Config
NewConfig returns a configuration struct fully populated with default values.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing configs that are in a map or slice the default values are still applied.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing configs that are in a map or slice the default values are still applied.
type DynamoDB ¶ added in v0.28.0
type DynamoDB struct {
// contains filtered or unexported fields
}
DynamoDB is a DynamoDB based cache implementation.
func (*DynamoDB) Add ¶ added in v0.28.0
Add attempts to set the value of a key only if the key does not already exist and returns an error if the key already exists.
type DynamoDBConfig ¶ added in v0.28.0
type DynamoDBConfig struct { ConsistentRead bool `json:"consistent_read" yaml:"consistent_read"` Credentials AmazonAWSCredentialsConfig `json:"credentials" yaml:"credentials"` DataKey string `json:"data_key" yaml:"data_key"` Endpoint string `json:"endpoint" yaml:"endpoint"` HashKey string `json:"hash_key" yaml:"hash_key"` Region string `json:"region" yaml:"region"` Table string `json:"table" yaml:"table"` TTL string `json:"ttl" yaml:"ttl"` TTLKey string `json:"ttl_key" yaml:"ttl_key"` }
DynamoDBConfig contains config fields for the DynamoDB cache type.
func NewDynamoDBConfig ¶ added in v0.28.0
func NewDynamoDBConfig() DynamoDBConfig
NewDynamoDBConfig creates a MemoryConfig populated with default values.
type Memcached ¶
type Memcached struct {
// contains filtered or unexported fields
}
Memcached is a cache that connects to memcached servers.
func (*Memcached) Add ¶
Add attempts to set the value of a key only if the key does not already exist and returns an error if the key already exists or if the operation fails.
type MemcachedConfig ¶
type MemcachedConfig struct { Addresses []string `json:"addresses" yaml:"addresses"` Prefix string `json:"prefix" yaml:"prefix"` TTL int32 `json:"ttl" yaml:"ttl"` Retries int `json:"retries" yaml:"retries"` RetryPeriodMS int `json:"retry_period_ms" yaml:"retry_period_ms"` }
MemcachedConfig is a config struct for a memcached connection.
func NewMemcachedConfig ¶
func NewMemcachedConfig() MemcachedConfig
NewMemcachedConfig returns a MemcachedConfig with default values.
type Memory ¶
Memory is a memory based cache implementation.
func (*Memory) Add ¶
Add attempts to set the value of a key only if the key does not already exist and returns an error if the key already exists.
type MemoryConfig ¶
type MemoryConfig struct { TTL int `json:"ttl" yaml:"ttl"` CompactionIntervalS int `json:"compaction_interval_s" yaml:"compaction_interval_s"` }
MemoryConfig contains config fields for the Memory cache type.
func NewMemoryConfig ¶
func NewMemoryConfig() MemoryConfig
NewMemoryConfig creates a MemoryConfig populated with default values.