cache

package
v0.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 32 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultGroupcacheConfig = GroupcacheConfig{
		MaxSize:       250 * 1024 * 1024,
		DNSSDResolver: dns.GolangResolverType,
		DNSInterval:   1 * time.Minute,
		Timeout:       2 * time.Second,
	}
)
View Source
var (
	DefaultInMemoryCacheConfig = InMemoryCacheConfig{
		MaxSize:     250 * 1024 * 1024,
		MaxItemSize: 125 * 1024 * 1024,
	}
)

Functions

func RegisterCacheStatsCollector added in v0.25.0

func RegisterCacheStatsCollector(galaxy *galaxycache.Galaxy, conf *GroupcacheConfig, reg prometheus.Registerer)

RegisterCacheStatsCollector registers a groupcache metrics collector.

Types

type AttributesConfig added in v0.25.0

type AttributesConfig struct {
	OperationConfig
	TTL time.Duration
}

type Cache

type Cache interface {
	// Store data into the cache.
	//
	// Note that individual byte buffers may be retained by the cache!
	Store(ctx context.Context, data map[string][]byte, ttl time.Duration)

	// Fetch multiple keys from cache. Returns map of input keys to data.
	// If key isn't in the map, data for given key was not found.
	Fetch(ctx context.Context, keys []string) map[string][]byte

	Name() string
}

Generic best-effort cache.

func NewTracingCache added in v0.14.0

func NewTracingCache(cache Cache) Cache

type CacheStatsCollector added in v0.25.0

type CacheStatsCollector struct {
	// contains filtered or unexported fields
}

func (*CacheStatsCollector) Collect added in v0.25.0

func (s *CacheStatsCollector) Collect(ch chan<- prometheus.Metric)

func (*CacheStatsCollector) Describe added in v0.25.0

func (s *CacheStatsCollector) Describe(ch chan<- *prometheus.Desc)

type CachingBucketConfig added in v0.25.0

type CachingBucketConfig struct {
	// contains filtered or unexported fields
}

CachingBucketConfig contains low-level configuration for individual bucket operations. This is not exposed to the user, but it is expected that code sets up individual operations based on user-provided configuration.

func NewCachingBucketConfig added in v0.25.0

func NewCachingBucketConfig() *CachingBucketConfig

func (*CachingBucketConfig) AllConfigNames added in v0.25.0

func (cfg *CachingBucketConfig) AllConfigNames() map[string][]string

func (*CachingBucketConfig) CacheAttributes added in v0.25.0

func (cfg *CachingBucketConfig) CacheAttributes(configName string, cache Cache, matcher func(name string) bool, ttl time.Duration)

CacheAttributes configures caching of "Attributes" operation for matching files.

func (*CachingBucketConfig) CacheExists added in v0.25.0

func (cfg *CachingBucketConfig) CacheExists(configName string, cache Cache, matcher func(string) bool, existsTTL, doesntExistTTL time.Duration)

CacheExists configures caching of "Exists" operation for matching files. Negative values are cached as well.

func (*CachingBucketConfig) CacheGet added in v0.25.0

func (cfg *CachingBucketConfig) CacheGet(configName string, cache Cache, matcher func(string) bool, maxCacheableSize int, contentTTL, existsTTL, doesntExistTTL time.Duration)

CacheGet configures caching of "Get" operation for matching files. Content of the object is cached, as well as whether object exists or not.

func (*CachingBucketConfig) CacheGetRange added in v0.25.0

func (cfg *CachingBucketConfig) CacheGetRange(configName string, cache Cache, matcher func(string) bool, subrangeSize int64, attributesTTL, subrangeTTL time.Duration, maxSubRequests int)

CacheGetRange configures caching of "GetRange" operation. Subranges (aligned on subrange size) are cached individually. Since caching operation needs to know the object size to compute correct subranges, object size is cached as well. Single "GetRange" requests can result in multiple smaller GetRange sub-requests issued on the underlying bucket. MaxSubRequests specifies how many such subrequests may be issued. Values <= 0 mean there is no limit (requests for adjacent missing subranges are still merged).

func (*CachingBucketConfig) CacheIter added in v0.25.0

func (cfg *CachingBucketConfig) CacheIter(configName string, cache Cache, matcher func(string) bool, ttl time.Duration, codec IterCodec)

CacheIter configures caching of "Iter" operation for matching directories.

func (*CachingBucketConfig) FindAttributesConfig added in v0.25.0

func (cfg *CachingBucketConfig) FindAttributesConfig(name string) (string, *AttributesConfig)

func (*CachingBucketConfig) FindExistConfig added in v0.25.0

func (cfg *CachingBucketConfig) FindExistConfig(name string) (string, *ExistsConfig)

func (*CachingBucketConfig) FindGetConfig added in v0.25.0

func (cfg *CachingBucketConfig) FindGetConfig(name string) (string, *GetConfig)

func (*CachingBucketConfig) FindGetRangeConfig added in v0.25.0

func (cfg *CachingBucketConfig) FindGetRangeConfig(name string) (string, *GetRangeConfig)

func (*CachingBucketConfig) FindIterConfig added in v0.25.0

func (cfg *CachingBucketConfig) FindIterConfig(dir string) (string, *IterConfig)

func (*CachingBucketConfig) SetCacheImplementation added in v0.25.0

func (cfg *CachingBucketConfig) SetCacheImplementation(c Cache)

SetCacheImplementation sets the value of Cache for all configurations.

type ExistsConfig added in v0.25.0

type ExistsConfig struct {
	OperationConfig
	ExistsTTL      time.Duration
	DoesntExistTTL time.Duration
}

type GetConfig added in v0.25.0

type GetConfig struct {
	ExistsConfig
	ContentTTL       time.Duration
	MaxCacheableSize int
}

type GetRangeConfig added in v0.25.0

type GetRangeConfig struct {
	OperationConfig
	SubrangeSize   int64
	MaxSubRequests int
	AttributesTTL  time.Duration
	SubrangeTTL    time.Duration
}

type Groupcache added in v0.25.0

type Groupcache struct {
	// contains filtered or unexported fields
}

func NewGroupcache added in v0.25.0

func NewGroupcache(logger log.Logger, reg prometheus.Registerer, conf []byte, basepath string, r *route.Router, bucket objstore.Bucket, cfg *CachingBucketConfig) (*Groupcache, error)

NewGroupcache creates a new Groupcache instance.

func NewGroupcacheWithConfig added in v0.25.0

func NewGroupcacheWithConfig(logger log.Logger, reg prometheus.Registerer, conf GroupcacheConfig, basepath string, r *route.Router, bucket objstore.Bucket,
	cfg *CachingBucketConfig) (*Groupcache, error)

NewGroupcacheWithConfig creates a new Groupcache instance with the given config.

func (*Groupcache) Fetch added in v0.25.0

func (c *Groupcache) Fetch(ctx context.Context, keys []string) map[string][]byte

func (*Groupcache) Name added in v0.25.0

func (c *Groupcache) Name() string

func (*Groupcache) Store added in v0.25.0

func (c *Groupcache) Store(ctx context.Context, data map[string][]byte, ttl time.Duration)

type GroupcacheConfig added in v0.25.0

type GroupcacheConfig struct {
	// Addresses of statically configured peers (repeatable). The scheme may be prefixed with 'dns+' or 'dnssrv+' to detect store API servers through respective DNS lookups.
	// Typically, you'd want something like `dns+http://thanos-store:42/`.
	Peers []string `yaml:"peers"`

	// Address of ourselves in the peer list. This needs to be set to `http://external-ip:HTTP_PORT`
	// of the current instance.
	SelfURL string `yaml:"self_url"`

	// Maximum size of the hot in-memory cache.
	MaxSize model.Bytes `yaml:"max_size"`

	// Group's name. All of the instances need to be using the same group and point to the same bucket.
	GroupcacheGroup string `yaml:"groupcache_group"`

	// DNS SD resolver to use.
	DNSSDResolver dns.ResolverType `yaml:"dns_sd_resolver"`

	// How often we should resolve the addresses.
	DNSInterval time.Duration `yaml:"dns_interval"`

	// Timeout specifies the read/write timeout.
	Timeout time.Duration `yaml:"timeout"`
}

GroupcacheConfig holds the in-memory cache config.

type InMemoryCache added in v0.19.0

type InMemoryCache struct {
	// contains filtered or unexported fields
}

func NewInMemoryCache added in v0.19.0

func NewInMemoryCache(name string, logger log.Logger, reg prometheus.Registerer, conf []byte) (*InMemoryCache, error)

NewInMemoryCache creates a new thread-safe LRU cache and ensures the total cache size approximately does not exceed maxBytes.

func NewInMemoryCacheWithConfig added in v0.19.0

func NewInMemoryCacheWithConfig(name string, logger log.Logger, reg prometheus.Registerer, config InMemoryCacheConfig) (*InMemoryCache, error)

NewInMemoryCacheWithConfig creates a new thread-safe LRU cache and ensures the total cache size approximately does not exceed maxBytes.

func (*InMemoryCache) Fetch added in v0.19.0

func (c *InMemoryCache) Fetch(ctx context.Context, keys []string) map[string][]byte

Fetch fetches multiple keys and returns a map containing cache hits In case of error, it logs and return an empty cache hits map.

func (*InMemoryCache) Name added in v0.24.0

func (c *InMemoryCache) Name() string

func (*InMemoryCache) Store added in v0.19.0

func (c *InMemoryCache) Store(ctx context.Context, data map[string][]byte, ttl time.Duration)

type InMemoryCacheConfig added in v0.19.0

type InMemoryCacheConfig struct {
	// MaxSize represents overall maximum number of bytes cache can contain.
	MaxSize model.Bytes `yaml:"max_size"`
	// MaxItemSize represents maximum size of single item.
	MaxItemSize model.Bytes `yaml:"max_item_size"`
}

InMemoryCacheConfig holds the in-memory cache config.

type IterCodec added in v0.25.0

type IterCodec interface {
	Encode(files []string) ([]byte, error)
	Decode(cachedData []byte) ([]string, error)
}

Codec for encoding and decoding results of Iter call.

type IterConfig added in v0.25.0

type IterConfig struct {
	OperationConfig
	TTL   time.Duration
	Codec IterCodec
}

Operation-specific configs.

type MemcachedCache

type MemcachedCache struct {
	// contains filtered or unexported fields
}

MemcachedCache is a memcached-based cache.

func NewMemcachedCache

func NewMemcachedCache(name string, logger log.Logger, memcached cacheutil.RemoteCacheClient, reg prometheus.Registerer) *MemcachedCache

NewMemcachedCache makes a new MemcachedCache.

func (*MemcachedCache) Fetch

func (c *MemcachedCache) Fetch(ctx context.Context, keys []string) map[string][]byte

Fetch fetches multiple keys and returns a map containing cache hits, along with a list of missing keys. In case of error, it logs and return an empty cache hits map.

func (*MemcachedCache) Name added in v0.24.0

func (c *MemcachedCache) Name() string

func (*MemcachedCache) Store

func (c *MemcachedCache) Store(ctx context.Context, data map[string][]byte, ttl time.Duration)

Store data identified by keys. The function enqueues the request and returns immediately: the entry will be asynchronously stored in the cache.

type OperationConfig added in v0.25.0

type OperationConfig struct {
	Matcher func(name string) bool
	Cache   Cache
}

Generic config for single operation.

type RedisCache added in v0.25.0

type RedisCache struct {
	// contains filtered or unexported fields
}

RedisCache is a redis cache.

func NewRedisCache added in v0.25.0

func NewRedisCache(name string, logger log.Logger, redisClient *cacheutil.RedisClient, reg prometheus.Registerer) *RedisCache

NewRedisCache makes a new RedisCache.

func (*RedisCache) Fetch added in v0.25.0

func (c *RedisCache) Fetch(ctx context.Context, keys []string) map[string][]byte

Fetch fetches multiple keys and returns a map containing cache hits, along with a list of missing keys. In case of error, it logs and return an empty cache hits map.

func (*RedisCache) Name added in v0.25.0

func (c *RedisCache) Name() string

func (*RedisCache) Store added in v0.25.0

func (c *RedisCache) Store(ctx context.Context, data map[string][]byte, ttl time.Duration)

Store data identified by keys.

type TracingCache added in v0.14.0

type TracingCache struct {
	// contains filtered or unexported fields
}

TracingCache includes Fetch operation in the traces.

func (TracingCache) Fetch added in v0.14.0

func (t TracingCache) Fetch(ctx context.Context, keys []string) (result map[string][]byte)

func (TracingCache) Name added in v0.24.0

func (t TracingCache) Name() string

func (TracingCache) Store added in v0.14.0

func (t TracingCache) Store(ctx context.Context, data map[string][]byte, ttl time.Duration)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL