lru

package
v1.63.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT 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 struct {
	// contains filtered or unexported fields
}

Cache wraps a ccache and allows setting custom metrics for hits/misses. duration and maxSize are initialized to their default values but should be configured using WithExpirationInterval and WithMaxSize options.

func New

func New(op string, opts ...Option) *Cache

New creates an LRU cache

func (*Cache) FindOrFetch

func (c *Cache) FindOrFetch(cacheNamespace, key string, fetchFn func() (interface{}, error)) (interface{}, error)

FindOrFetch will try to get the item from the cache if exists and is not expired. If it can't find it, it will call fetchFn to retrieve the item and cache it.

type Option added in v1.49.0

type Option func(*Cache)

Option function to configure a Cache

func WithCachedEntriesMetric added in v1.49.0

func WithCachedEntriesMetric(m *prometheus.GaugeVec) Option

func WithCachedRequestsMetric added in v1.49.0

func WithCachedRequestsMetric(m *prometheus.CounterVec) Option

func WithExpirationInterval added in v1.49.0

func WithExpirationInterval(t time.Duration) Option

func WithMaxSize added in v1.49.0

func WithMaxSize(i int64) Option

Jump to

Keyboard shortcuts

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