cache

package
v0.0.0-...-d1b097e Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

This package implements an image metadata cache given a backing k-v store.

The interface `Client` stands in for the k-v store (e.g., memcached, in the subpackage); `Cache` implements registry.Registry given a `Client`.

The `Warmer` is for continually refreshing the cache by fetching new metadata from the original image registries.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotCached = &fluxerr.Error{
		Type: fluxerr.Missing,
		Err:  errors.New("item not in cache"),
		Help: `Image not yet cached

It takes time to initially cache all the images. Please wait.

If you have waited for a long time, check the flux logs. Potential
reasons for the error are: no internet, no cache, error with the remote
repository.
`,
	}
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Reader Reader
}

Cache is a local cache of image metadata.

func (*Cache) GetImage

func (c *Cache) GetImage(id image.Ref) (image.Info, error)

GetImage gets the manifest of a specific image ref, from its registry.

func (*Cache) GetRepositoryImages

func (c *Cache) GetRepositoryImages(id image.Name) ([]image.Info, error)

GetRepositoryImages returns the list of image manifests in an image repository (e.g,. at "quay.io/weaveworks/flux")

type Client

type Client interface {
	Reader
	Writer
}

func InstrumentClient

func InstrumentClient(c Client) Client

type ImageRepository

type ImageRepository struct {
	LastError  string
	LastUpdate time.Time
	Images     map[string]image.Info
}

ImageRepository holds the last good information on an image repository.

Whenever we successfully fetch a full set of image info, `LastUpdate` and `Images` shall each be assigned a value, and `LastError` will be cleared.

If we cannot for any reason obtain a full set of image info, `LastError` shall be assigned a value, and the other fields left alone.

It's possible to have all fields populated: this means at some point it was successfully fetched, but since then, there's been an error. It's then up to the caller to decide what to do with the value (show the images, but also indicate there's a problem, for example).

type Keyer

type Keyer interface {
	Key() string
}

An interface to provide the key under which to store the data Use the full path to image for the memcache key because there might be duplicates from other registries

func NewManifestKey

func NewManifestKey(image image.CanonicalRef) Keyer

func NewRepositoryKey

func NewRepositoryKey(repo image.CanonicalName) Keyer

type Reader

type Reader interface {
	// GetKey gets the value at a key, along with its refresh deadline
	GetKey(k Keyer) ([]byte, time.Time, error)
}

type StringSet

type StringSet map[string]struct{}

StringSet is a set of strings.

func NewStringSet

func NewStringSet(ss []string) StringSet

NewStringSet returns a StringSet containing exactly the strings given as arguments.

func (StringSet) Subset

func (s StringSet) Subset(t StringSet) bool

Subset returns true if `s` is a subset of `t` (including the case of having the same members).

type Warmer

type Warmer struct {
	Trace    bool
	Priority chan image.Name
	Notify   func()
	// contains filtered or unexported fields
}

Warmer refreshes the information kept in the cache from remote registries.

func NewWarmer

func NewWarmer(cf registry.ClientFactory, cacheClient Client, burst int) (*Warmer, error)

NewWarmer creates cache warmer that (when Loop is invoked) will periodically refresh the values kept in the cache.

func (*Warmer) Loop

func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGroup, imagesToFetchFunc func() registry.ImageCreds)

Loop continuously gets the images to populate the cache with, and populate the cache with them.

type Writer

type Writer interface {
	// SetKey sets the value at a key, along with its refresh deadline
	SetKey(k Keyer, deadline time.Time, v []byte) error
}

Directories

Path Synopsis
This package implements an image DB cache using memcached.
This package implements an image DB cache using memcached.

Jump to

Keyboard shortcuts

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