rtcache

package
v0.0.0-...-c8d90df Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemReadThroughCache

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

MemReadThroughCache implements the ReadThroughCache interface.

func New

func New(rtf ReadThroughFunc, maxCachedItems int, maxConcurrentReadThroughCalls int) (*MemReadThroughCache, error)

New returns a new instance of ReadThroughCache that is stored in RAM. maxConcurrentReadThroughCalls defines the number of concurrent calls to the ReadThroughFunc when requested items are not cached.

func (*MemReadThroughCache) Contains

func (m *MemReadThroughCache) Contains(id string) bool

Contains implements the ReadThroughCache interface.

func (*MemReadThroughCache) Get

func (m *MemReadThroughCache) Get(ctx context.Context, id string) (interface{}, error)

Get implements the ReadThroughCache interface.

func (*MemReadThroughCache) GetAll

func (m *MemReadThroughCache) GetAll(ctx context.Context, ids []string) ([]interface{}, error)

GetAll implements the ReadThroughCache interface.

func (*MemReadThroughCache) Keys

func (m *MemReadThroughCache) Keys() []string

Keys implements the ReadThroughCache interface.

func (*MemReadThroughCache) Len

func (m *MemReadThroughCache) Len() int

Len implements the ReadThroughCache interface.

func (*MemReadThroughCache) Remove

func (m *MemReadThroughCache) Remove(ids []string)

Remove implements the ReadThroughCache interface.

type ReadThroughCache

type ReadThroughCache interface {
	// Get returns the item identified by 'id' or an error if the item
	// cannot be retrieved. If the item is not in the cache a worker function
	// is called to retrieve it.
	Get(ctx context.Context, id string) (interface{}, error)

	// GetAll returns all items identified by 'ids' or an error if any of them
	// cannot be retrieved. If any items are not in the cache, a worker function
	// is called per item to retrieve them.
	GetAll(ctx context.Context, ids []string) ([]interface{}, error)

	// Len returns the number of items that are cached.
	Len() int

	// Keys returns the keys of the items that are cached.
	Keys() []string

	// Contains returns true if the identified item is currently cached.
	Contains(id string) bool

	// Remove removes the element with the given ids from the cache.
	Remove(ids []string)
}

ReadThroughCache defines a caching work queue with priorities. If the item identified by 'id' is not in the cache then it will call a provided ReadThroughFunc in order to calculate it.

type ReadThroughFunc

type ReadThroughFunc func(ctx context.Context, ids []string) ([]interface{}, error)

ReadThroughFunc defines the function that is called when an item is not in the cache. 'ctx' and 'ids' are the same that were passed to Get(...). error might be wrapped.

Jump to

Keyboard shortcuts

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