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 NewFile(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 NewRedis(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
- func NewS3(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
- func SanitiseConfig(conf Config) (interface{}, error)
- type Config
- type DynamoDB
- type DynamoDBConfig
- type File
- type FileConfig
- type Memcached
- type MemcachedConfig
- type Memory
- type MemoryConfig
- type Redis
- type RedisConfig
- type S3
- type S3Config
- type TypeSpec
Constants ¶
const ( TypeDynamoDB = "dynamodb" TypeFile = "file" TypeMemcached = "memcached" TypeMemory = "memory" TypeRedis = "redis" TypeS3 = "s3" )
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 NewFile ¶ added in v1.12.0
func NewFile(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
NewFile creates a new File 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 NewRedis ¶ added in v0.34.7
func NewRedis( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (types.Cache, error)
NewRedis returns a Redis processor.
func NewS3 ¶ added in v1.12.0
func NewS3(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)
NewS3 creates a new S3 cache type.
func SanitiseConfig ¶ added in v0.16.2
SanitiseConfig creates a sanitised version of a config.
Types ¶
type Config ¶
type Config struct { Type string `json:"type" yaml:"type"` DynamoDB DynamoDBConfig `json:"dynamodb" yaml:"dynamodb"` File FileConfig `json:"file" yaml:"file"` Memcached MemcachedConfig `json:"memcached" yaml:"memcached"` Memory MemoryConfig `json:"memory" yaml:"memory"` Redis RedisConfig `json:"redis" yaml:"redis"` S3 S3Config `json:"s3" yaml:"s3"` }
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.
func (*DynamoDB) Get ¶ added in v0.28.0
Get attempts to locate and return a cached value by its key, returns an error if the key does not exist.
type DynamoDBConfig ¶ added in v0.28.0
type DynamoDBConfig struct { ConsistentRead bool `json:"consistent_read" yaml:"consistent_read"` DataKey string `json:"data_key" yaml:"data_key"` HashKey string `json:"hash_key" yaml:"hash_key"` Table string `json:"table" yaml:"table"` TTL string `json:"ttl" yaml:"ttl"` TTLKey string `json:"ttl_key" yaml:"ttl_key"` retries.Config `json:",inline" yaml:",inline"` // contains filtered or unexported fields }
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 File ¶ added in v1.12.0
type File struct {
// contains filtered or unexported fields
}
File is a file system based cache implementation.
func (*File) Add ¶ added in v1.12.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.
func (*File) Get ¶ added in v1.12.0
Get attempts to locate and return a cached value by its key, returns an error if the key does not exist.
type FileConfig ¶ added in v1.12.0
type FileConfig struct {
Directory string `json:"directory" yaml:"directory"`
}
FileConfig contains config fields for the File cache type.
func NewFileConfig ¶ added in v1.12.0
func NewFileConfig() FileConfig
NewFileConfig creates a FileConfig 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.
func (*Memcached) Get ¶
Get attempts to locate and return a cached value by its key, returns an error if the key does not exist or if the operation failed.
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"` RetryPeriod string `json:"retry_period" yaml:"retry_period"` }
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.
func (*Memory) Get ¶
Get attempts to locate and return a cached value by its key, returns an error if the key does not exist.
type MemoryConfig ¶
type MemoryConfig struct { TTL int `json:"ttl" yaml:"ttl"` CompactionInterval string `json:"compaction_interval" yaml:"compaction_interval"` }
MemoryConfig contains config fields for the Memory cache type.
func NewMemoryConfig ¶
func NewMemoryConfig() MemoryConfig
NewMemoryConfig creates a MemoryConfig populated with default values.
type Redis ¶ added in v0.34.7
type Redis struct {
// contains filtered or unexported fields
}
Redis is a cache that connects to redis servers.
func (*Redis) Add ¶ added in v0.34.7
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.
func (*Redis) Get ¶ added in v0.34.7
Get attempts to locate and return a cached value by its key, returns an error if the key does not exist or if the operation failed.
type RedisConfig ¶ added in v0.34.7
type RedisConfig struct { URL string `json:"url" yaml:"url"` Prefix string `json:"prefix" yaml:"prefix"` Expiration string `json:"expiration" yaml:"expiration"` Retries int `json:"retries" yaml:"retries"` RetryPeriod string `json:"retry_period" yaml:"retry_period"` }
RedisConfig is a config struct for a redis connection.
func NewRedisConfig ¶ added in v0.34.7
func NewRedisConfig() RedisConfig
NewRedisConfig returns a RedisConfig with default values.
type S3 ¶ added in v1.12.0
type S3 struct {
// contains filtered or unexported fields
}
S3 is a file system based cache implementation.
func (*S3) Add ¶ added in v1.12.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.
func (*S3) Get ¶ added in v1.12.0
Get attempts to locate and return a cached value by its key, returns an error if the key does not exist.
type S3Config ¶ added in v1.12.0
type S3Config struct { sess.Config `json:",inline" yaml:",inline"` Bucket string `json:"bucket" yaml:"bucket"` ContentType string `json:"content_type" yaml:"content_type"` Timeout string `json:"timeout" yaml:"timeout"` Retries int `json:"retries" yaml:"retries"` }
S3Config contains config fields for the S3 cache type.
func NewS3Config ¶ added in v1.12.0
func NewS3Config() S3Config
NewS3Config creates a S3Config populated with default values.