cache

package
v1.17.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	storage.BatchedStore
	// contains filtered or unexported fields
}

Cache is a wrapper around a storage.Store that adds a layer of in-memory caching for the Get and Has operations.

func MustWrap

func MustWrap(store storage.BatchedStore, capacity int) *Cache

MustWrap is like Wrap but panics on error.

func Wrap

func Wrap(store storage.BatchedStore, capacity int) (*Cache, error)

Wrap adds a layer of in-memory caching to storage.Reader Get and Has operations. It returns an error if the capacity is less than or equal to zero or if the given store implements storage.Tx

func (*Cache) Delete

func (c *Cache) Delete(i storage.Item) error

Delete implements storage.Store interface. On a call it also removes the item from the cache.

func (*Cache) Get

func (c *Cache) Get(i storage.Item) error

Get implements storage.Store interface. On a call it tries to first retrieve the item from cache. If the item does not exist in cache, it tries to retrieve it from the underlying store.

func (*Cache) Has

func (c *Cache) Has(k storage.Key) (bool, error)

Has implements storage.Store interface. On a call it tries to first retrieve the item from cache. If the item does not exist in cache, it tries to retrieve it from the underlying store.

func (*Cache) Metrics

func (c *Cache) Metrics() []prometheus.Collector

func (*Cache) Put

func (c *Cache) Put(i storage.Item) error

Put implements storage.Store interface. On a call it also inserts the item into the cache so that the next call to Put and Has will be able to retrieve the item from cache.

Jump to

Keyboard shortcuts

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