cache

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 3 Imported by: 6

Documentation

Overview

Package cache implements an inmemory cache for any interface{} object.

Although exported, this package is non intended for general consumption. It is a shared dependency between multiple exposure notifications projects. We cannot guarantee that there won't be breaking changes in the future.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDuration = errors.New("expireAfter duration cannot be negative")

Functions

This section is empty.

Types

type Cache

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

func New

func New(expireAfter time.Duration) (*Cache, error)

New creates a new in memory cache.

func (*Cache) Clear added in v0.26.0

func (c *Cache) Clear()

Clear removes all items from the cache, regardless of their expiration.

func (*Cache) Lookup

func (c *Cache) Lookup(name string) (interface{}, bool)

Lookup checks the cache for a non-expired object by the supplied key name. The bool return informs the caller if there was a cache hit or not. A return of nil, true means that nil is in the cache. Where nil, false indicates a cache miss or that the value is expired and should be refreshed.

func (*Cache) Set

func (c *Cache) Set(name string, object interface{}) error

Set saves the current value of an object in the cache, with the supplied durintion until the object expires.

func (*Cache) Size

func (c *Cache) Size() int

Size returns the number of items in the cache.

func (*Cache) WriteThruLookup

func (c *Cache) WriteThruLookup(name string, primaryLookup Func) (interface{}, error)

WriteThruLookup checks the cache for the value associated with name, and if not found or expired, invokes the provided primaryLookup function to local the value.

type Func

type Func func() (interface{}, error)

Jump to

Keyboard shortcuts

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