{"modulePath":"github.com/benthosdev/benthos","version":"v0.26.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cache\n\nPackage cache implements the types.Cache interface for storing and retrieving key/value pairs from a range of storage strategies.\n\n## Constants\n\n```go\nconst (\n\tTypeMemcached = \"memcached\"\n\tTypeMemory    = \"memory\"\n)\n```\nString constants representing each cache type.\n\n## Variables\n\n```go\nvar Constructors = map[string]TypeSpec{}\n```\nConstructors is a map of all cache types with their specs.\n\n## Functions\n\n```go\nfunc Descriptions() string\n```\nDescriptions returns a formatted string of descriptions for each type.\n\n```go\nfunc New(\n\tconf Config,\n\tmgr types.Manager,\n\tlog log.Modular,\n\tstats metrics.Type,\n) (types.Cache, error)\n```\nNew creates a cache type based on an cache configuration.\n\n```go\nfunc NewMemcached(\n\tconf Config, mgr types.Manager, log log.Modular, stats metrics.Type,\n) (types.Cache, error)\n```\nNewMemcached returns a Memcached processor.\n\n```go\nfunc NewMemory(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.Cache, error)\n```\nNewMemory creates a new Memory cache type.\n\n```go\nfunc SanitiseConfig(conf Config) (interface{}, error)\n```\nSanitiseConfig creates a sanitised version of a config.\n\n## Types\n\n```go\ntype Config struct {\n\tType      string          `json:\"type\" yaml:\"type\"`\n\tMemcached MemcachedConfig `json:\"memcached\" yaml:\"memcached\"`\n\tMemory    MemoryConfig    `json:\"memory\" yaml:\"memory\"`\n}\n```\nConfig is the all encompassing configuration struct for all cache types.\n\n```go\nfunc NewConfig() Config\n```\nNewConfig returns a configuration struct fully populated with default values.\n\n```go\nfunc (c *Config) UnmarshalJSON(bytes []byte) error\n```\nUnmarshalJSON ensures that when parsing configs that are in a map or slice the default values are still applied.\n\n```go\nfunc (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error\n```\nUnmarshalYAML ensures that when parsing configs that are in a map or slice the default values are still applied.\n\n```go\ntype Memcached struct {\n\t// contains filtered or unexported fields\n}\n```\nMemcached is a cache that connects to memcached servers.\n\n```go\nfunc (m *Memcached) Add(key string, value []byte) error\n```\nAdd 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.\n\n```go\nfunc (m *Memcached) Delete(key string) error\n```\nDelete attempts to remove a key.\n\n```go\nfunc (m *Memcached) Get(key string) ([]byte, error)\n```\nGet 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.\n\n```go\nfunc (m *Memcached) Set(key string, value []byte) error\n```\nSet attempts to set the value of a key.\n\n```go\ntype MemcachedConfig struct {\n\tAddresses     []string `json:\"addresses\" yaml:\"addresses\"`\n\tPrefix        string   `json:\"prefix\" yaml:\"prefix\"`\n\tTTL           int32    `json:\"ttl\" yaml:\"ttl\"`\n\tRetries       int      `json:\"retries\" yaml:\"retries\"`\n\tRetryPeriodMS int      `json:\"retry_period_ms\" yaml:\"retry_period_ms\"`\n}\n```\nMemcachedConfig is a config struct for a memcached connection.\n\n```go\nfunc NewMemcachedConfig() MemcachedConfig\n```\nNewMemcachedConfig returns a MemcachedConfig with default values.\n\n```go\ntype Memory struct {\n\tsync.RWMutex\n\t// contains filtered or unexported fields\n}\n```\nMemory is a memory based cache implementation.\n\n```go\nfunc (m *Memory) Add(key string, value []byte) error\n```\nAdd 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.\n\n```go\nfunc (m *Memory) Delete(key string) error\n```\nDelete attempts to remove a key.\n\n```go\nfunc (m *Memory) Get(key string) ([]byte, error)\n```\nGet attempts to locate and return a cached value by its key, returns an error if the key does not exist.\n\n```go\nfunc (m *Memory) Set(key string, value []byte) error\n```\nSet attempts to set the value of a key.\n\n```go\ntype MemoryConfig struct {\n\tTTL                 int `json:\"ttl\" yaml:\"ttl\"`\n\tCompactionIntervalS int `json:\"compaction_interval_s\" yaml:\"compaction_interval_s\"`\n}\n```\nMemoryConfig contains config fields for the Memory cache type.\n\n```go\nfunc NewMemoryConfig() MemoryConfig\n```\nNewMemoryConfig creates a MemoryConfig populated with default values.\n\n```go\ntype TypeSpec struct {\n\t// contains filtered or unexported fields\n}\n```\nTypeSpec is a constructor and a usage description for each input type.\n\n","path":"github.com/benthosdev/benthos/lib/cache","name":"cache","synopsis":"Package cache implements the types.Cache interface for storing and retrieving key/value pairs from a range of storage strategies.","isRedistributable":true}
