cache

package
v0.0.0-...-eb12069 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: BSD-3-Clause Imports: 5 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 {
	storage.Store
	// 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 Wrap

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

Wrap adds a layer of in-memory caching to basic Store operations. This call will panic if the capacity is less than or equal to zero. It will also panic 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