cache

package
v16.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package cache supplies background workers for periodically cleaning the cache folder on all storages listed in the config file. Upon configuration validation, one worker will be started for each storage. The worker will walk the cache directory tree and remove any files older than one hour. The worker will walk the cache directory every ten minutes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingLeaseFile indicates a lease file does not exist on the
	// filesystem that the lease ender expected to be there
	ErrMissingLeaseFile = errors.New("lease file unexpectedly missing")
	// ErrInvalidUUID indicates an internal error with generating a UUID
	ErrInvalidUUID = errors.New("unable to generate valid UUID")
	// ErrCtxMethodMissing indicates the provided context does not contain the
	// expected information about the current gRPC method
	ErrCtxMethodMissing = errors.New("context does not contain gRPC method name")
	// ErrPendingExists indicates that there is a critical zone for the current
	// repository in the pending transition
	ErrPendingExists = errors.New("one or more cache generations are pending transition for the current repository")
)
View Source
var ErrReqNotFound = errors.New("request digest not found within repo namespace")

ErrReqNotFound indicates the request does not exist within the repo digest

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Streamer
	Invalidator
}

Cache is a stream-oriented cache which stores RPC responses keyed by protobuf requests.

type DiskCache

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

DiskCache stores and retrieves byte streams for repository related RPCs

func New

func New(cfg config.Cfg, locator storage.Locator, logger log.Logger, opts ...Option) *DiskCache

New will create a new DiskCache with the given Keyer.

func (*DiskCache) Collect

func (c *DiskCache) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*DiskCache) Describe

func (c *DiskCache) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*DiskCache) GetStream

func (c *DiskCache) GetStream(ctx context.Context, repo *gitalypb.Repository, req proto.Message) (_ io.ReadCloser, err error)

GetStream will fetch the cached stream for a request. It is the responsibility of the caller to close the stream when done.

func (*DiskCache) KeyPath

func (c *DiskCache) KeyPath(ctx context.Context, repo *gitalypb.Repository, req proto.Message) (string, error)

KeyPath returns the cache path for the given request.

func (*DiskCache) PutStream

func (c *DiskCache) PutStream(ctx context.Context, repo *gitalypb.Repository, req proto.Message, src io.Reader) (returnedErr error)

PutStream will store a stream in a repo-namespace keyed by the digest of the request protobuf message.

func (*DiskCache) StartLease

func (c *DiskCache) StartLease(repo *gitalypb.Repository) (LeaseEnder, error)

StartLease will mark the repository as being in an indeterministic state. This is typically used when modifying the repo, since the cache is not stable until after the modification is complete. A lease object will be returned that allows the caller to signal the end of the lease.

func (*DiskCache) StartWalkers

func (c *DiskCache) StartWalkers() error

StartWalkers starts the cache walker Goroutines. Initially, this function will try to clean up any preexisting cache directories.

func (*DiskCache) StopWalkers

func (c *DiskCache) StopWalkers()

StopWalkers stops all walkers started by StartWalkers.

type Invalidator

type Invalidator interface {
	StartLease(*gitalypb.Repository) (LeaseEnder, error)
}

Invalidator is able to invalidate parts of the cache pertinent to a specific repository. Before a repo mutating operation, StartLease should be called. Once the operation is complete, the returned LeaseEnder should be invoked to end the lease.

type LeaseEnder

type LeaseEnder interface {
	EndLease(context.Context) error
}

LeaseEnder allows the caller to indicate when a lease is no longer needed

type Option

type Option func(*cacheConfig)

Option is an option for the cache.

type Streamer

type Streamer interface {
	GetStream(context.Context, *gitalypb.Repository, proto.Message) (io.ReadCloser, error)
	PutStream(context.Context, *gitalypb.Repository, proto.Message, io.Reader) error
}

Streamer abstracts away the cache concrete type so that it can be override in tests.

Jump to

Keyboard shortcuts

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