cache

package
v0.0.0-...-0611383 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cache provides a public interface and implementation for an in-memory cache that keeps the most recent response from the control plane per aggregated key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Fetch returns the cached resource if it exists.
	Fetch(key string) (*Resource, error)

	// SetResponse sets the cache response and returns the list of requests.
	SetResponse(key string, resp transport.Response) (*RequestsStore, error)

	// AddRequest adds the request to the cache.
	AddRequest(key string, req transport.Request) error

	// DeleteRequest removes the given request from any cache entries it's present in.
	DeleteRequest(key string, req transport.Request) error

	// DeleteKey removes the given key from cache.
	DeleteKey(key string) error

	// GetReadOnlyCache returns a copy of the cache that only exposes read-only methods in its interface.
	GetReadOnlyCache() ReadOnlyCache
}

func NewCache

func NewCache(maxEntries int, onEvicted OnEvictFunc, ttl time.Duration,
	logger log.Logger, scope tally.Scope) (Cache, error)

type OnEvictFunc

type OnEvictFunc func(key string, value Resource)

OnEvictFunc is a callback function for each eviction. Receives the key and cache value when called.

type ReadOnlyCache

type ReadOnlyCache interface {
	// Fetch returns the cached resource if it exists.
	FetchReadOnly(key string) (Resource, error)
}

type RequestsStore

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

func NewRequestsStore

func NewRequestsStore() *RequestsStore

func (*RequestsStore) Delete

func (m *RequestsStore) Delete(r transport.Request)

func (*RequestsStore) ForEach

func (m *RequestsStore) ForEach(f func(key transport.Request))

func (*RequestsStore) Set

func (m *RequestsStore) Set(r transport.Request)

type Resource

type Resource struct {
	Resp           transport.Response
	Requests       *RequestsStore
	ExpirationTime time.Time
}

Jump to

Keyboard shortcuts

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