cache

package
v0.0.0-...-57701fa Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: BSD-2-Clause-Patent Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpirableItem

type ExpirableItem interface {
	Item
	IsExpired() bool
}

ExpirableItem is an Item that defines its own expiration criteria.

type Item

type Item interface {
	sync.Locker
	Key() string
}

Item defines an interface for a cached item.

type ItemCache

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

ItemCache is a mechanism for caching Items to keys.

func NewItemCache

func NewItemCache(log logging.Logger) *ItemCache

NewItemCache creates a new ItemCache.

func (*ItemCache) Delete

func (ic *ItemCache) Delete(key string)

Delete fully deletes an Item from the cache.

func (*ItemCache) Get

func (ic *ItemCache) Get(ctx context.Context, key string) (Item, func(), error)

Get returns an item from the cache if it exists, otherwise it returns an error. The item must be released by the caller when it is safe to be modified.

func (*ItemCache) GetOrCreate

func (ic *ItemCache) GetOrCreate(ctx context.Context, key string, missFn ItemCreateFunc) (Item, func(), error)

GetOrCreate returns an item from the cache if it exists, otherwise it creates the item using the given function and caches it. The item must be released by the caller when it is safe to be modified.

func (*ItemCache) Has

func (ic *ItemCache) Has(key string) bool

Has checks whether any item is cached under the given key.

func (*ItemCache) Keys

func (ic *ItemCache) Keys() []string

Keys returns a sorted list of all keys in the cache.

func (*ItemCache) Refresh

func (ic *ItemCache) Refresh(ctx context.Context, keys ...string) error

Refresh forces a re-fetch of all items in the cache.

func (*ItemCache) Set

func (ic *ItemCache) Set(item Item) error

Set caches an item under a given key.

type ItemCreateFunc

type ItemCreateFunc func() (Item, error)

type RefreshableItem

type RefreshableItem interface {
	Item
	Refresh(ctx context.Context) error
	RefreshIfNeeded(ctx context.Context) (bool, error)
}

RefreshableItem is an Item that defines its own refresh criteria and method.

Jump to

Keyboard shortcuts

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