bucketcache

package
v0.0.0-...-80e4d6b Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCacheLookupEnabled

func WithCacheLookupEnabled(ctx context.Context, enabled bool) context.Context

WithCacheLookupEnabled returns a new context which will explicitly enable/disable the cache lookup but keep storing the result to the cache. The cache lookup is enabled by default.

func WithMemoryPool

func WithMemoryPool(ctx context.Context, p pool.Interface, slabSize int) context.Context

WithMemoryPool returns a new context with a slab pool to be used as a cache.Allocator implementation by the underlying cache client. Slabs are released back to p when the io.ReadCloser associated with the Get or GetRange call is closed.

Types

type CachingBucket

type CachingBucket struct {
	objstore.Bucket
	// contains filtered or unexported fields
}

CachingBucket implementation that provides some caching features, based on passed configuration.

func NewCachingBucket

func NewCachingBucket(bucketID string, bucketClient objstore.Bucket, cfg *CachingBucketConfig, logger log.Logger, reg prometheus.Registerer) (*CachingBucket, error)

NewCachingBucket creates new caching bucket with provided configuration. Configuration should not be changed after creating caching bucket.

func (*CachingBucket) Attributes

func (cb *CachingBucket) Attributes(ctx context.Context, name string) (objstore.ObjectAttributes, error)

func (*CachingBucket) Delete

func (cb *CachingBucket) Delete(ctx context.Context, name string) error

func (*CachingBucket) Exists

func (cb *CachingBucket) Exists(ctx context.Context, name string) (bool, error)

func (*CachingBucket) Get

func (cb *CachingBucket) Get(ctx context.Context, name string) (io.ReadCloser, error)

func (*CachingBucket) GetRange

func (cb *CachingBucket) GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error)

func (*CachingBucket) IsObjNotFoundErr

func (cb *CachingBucket) IsObjNotFoundErr(err error) bool

func (*CachingBucket) Iter

func (cb *CachingBucket) Iter(ctx context.Context, dir string, f func(string) error, options ...objstore.IterOption) error

func (*CachingBucket) Name

func (cb *CachingBucket) Name() string

func (*CachingBucket) ReaderWithExpectedErrs

func (cb *CachingBucket) ReaderWithExpectedErrs(expectedFunc objstore.IsOpFailureExpectedFunc) objstore.BucketReader

func (*CachingBucket) Upload

func (cb *CachingBucket) Upload(ctx context.Context, name string, r io.Reader) error

func (*CachingBucket) WithExpectedErrs

func (cb *CachingBucket) WithExpectedErrs(expectedFunc objstore.IsOpFailureExpectedFunc) objstore.Bucket

type CachingBucketConfig

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

func NewCachingBucketConfig() *CachingBucketConfig

func (*CachingBucketConfig) CacheAttributes

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

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

func (*CachingBucketConfig) CacheExists

func (cfg *CachingBucketConfig) CacheExists(configName string, cache 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

func (cfg *CachingBucketConfig) CacheGet(configName string, cache 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

func (cfg *CachingBucketConfig) CacheGetRange(configName string, cache cache.Cache, matcher func(string) bool, subrangeSize int64, attributesCache cache.Cache, 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

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

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

type IterCodec

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

IterCodec is a codec for encoding and decoding results of Iter call.

type JSONIterCodec

type JSONIterCodec struct{}

JSONIterCodec encodes iter results into JSON. Suitable for root dir.

func (JSONIterCodec) Decode

func (jic JSONIterCodec) Decode(data []byte) ([]string, error)

func (JSONIterCodec) Encode

func (jic JSONIterCodec) Encode(files []string) ([]byte, error)

type SnappyIterCodec

type SnappyIterCodec struct {
	IterCodec
}

func (SnappyIterCodec) Decode

func (i SnappyIterCodec) Decode(cachedData []byte) ([]string, error)

func (SnappyIterCodec) Encode

func (i SnappyIterCodec) Encode(files []string) ([]byte, error)

Jump to

Keyboard shortcuts

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