stored_requests

package
v0.0.0-...-018946c Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get works much like Fetcher.FetchRequests, with a few exceptions:
	//
	// 1. Any (actionable) errors should be logged by the implementation, rather than returned.
	// 2. The returned maps _may_ be written to.
	// 3. The returned maps must _not_ contain keys unless they were present in the argument ID list.
	// 4. Callers _should not_ assume that the returned maps contain key for every argument id.
	//    The returned map will miss entries for keys which don't exist in the cache.
	//
	// Nil slices and empty strings are treated as "no ops". That is, a nil requestID will always produce a nil
	// "stored request data" in the response.
	Get(ctx context.Context, requestIDs []string, impIDs []string) (requestData map[string]json.RawMessage, impData map[string]json.RawMessage)

	// Invalidate will ensure that all values associated with the given IDs
	// are no longer returned by the cache until new values are saved via Update
	Invalidate(ctx context.Context, requestIDs []string, impIDs []string)

	// Save will add or overwrite the data in the cache at the given keys
	Save(ctx context.Context, requestData map[string]json.RawMessage, impData map[string]json.RawMessage)
}

Cache is an intermediate layer which can be used to create more complex Fetchers by composition. Implementations must be safe for concurrent access by multiple goroutines. To add a Cache layer in front of a Fetcher, see WithCache()

type ComposedCache

type ComposedCache []Cache

ComposedCache creates an interface to treat a slice of caches as a single cache

func (ComposedCache) Get

func (c ComposedCache) Get(ctx context.Context, requestIDs []string, impIDs []string) (requestData map[string]json.RawMessage, impData map[string]json.RawMessage)

Get will attempt to Get from the caches in the order in which they are in the slice, stopping as soon as a value is found (or when all caches have been exhausted)

func (ComposedCache) Invalidate

func (c ComposedCache) Invalidate(ctx context.Context, requestIDs []string, impIDs []string)

Invalidate will propagate invalidations to all underlying caches

func (ComposedCache) Save

func (c ComposedCache) Save(ctx context.Context, requestData map[string]json.RawMessage, impData map[string]json.RawMessage)

Save will propagate saves to all underlying caches

type Fetcher

type Fetcher interface {
	// FetchRequests fetches the stored requests for the given IDs.
	//
	// The first return value will be the Stored Request data, or nil if it doesn't exist.
	// If requestID is an empty string, then this value will always be nil.
	//
	// The second return value will be a map from Stored Imp data. It will have a key for every ID
	// in the impIDs list, unless errors exist.
	//
	// The returned objects can only be read from. They may not be written to.
	FetchRequests(ctx context.Context, requestIDs []string, impIDs []string) (requestData map[string]json.RawMessage, impData map[string]json.RawMessage, errs []error)
}

Fetcher knows how to fetch Stored Request data by id.

Implementations must be safe for concurrent access by multiple goroutines. Callers are expected to share a single instance as much as possible.

func WithCache

func WithCache(fetcher Fetcher, cache Cache) Fetcher

WithCache returns a Fetcher which uses the given Cache before delegating to the original. This can be called multiple times to compose Cache layers onto the backing Fetcher, though it is usually more desirable to first compose caches with Compose, ensuring propagation of updates and invalidations through all cache layers.

type MultiFetcher

type MultiFetcher []Fetcher

MultiFetcher is a Fetcher composed of multiple sub-Fetchers that are all polled for results.

func (MultiFetcher) FetchRequests

func (mf MultiFetcher) FetchRequests(ctx context.Context, requestIDs []string, impIDs []string) (requestData map[string]json.RawMessage, impData map[string]json.RawMessage, errs []error)

FetchRequests implements the Fetcher interface for MultiFetcher

type NotFoundError

type NotFoundError struct {
	ID       string
	DataType string
}

NotFoundError is an error type to flag that an ID was not found by the Fetcher. This was added to support Multifetcher and any other case where we might expect that all IDs would not be found, and want to disentangle those errors from the others.

func (NotFoundError) Error

func (e NotFoundError) Error() string

Directories

Path Synopsis
backends
caches
api

Jump to

Keyboard shortcuts

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