cache

package
v0.0.0-...-e3ed143 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT 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[K comparable, V any] interface {
	Set(key K, val V)
	Get(key K) (V, bool)
	Delete(del func(key K, val V) bool)
}

Cache is a very broad cache interface to support an array of underlying implementations.

type CopyOnWriteCache

type CopyOnWriteCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

CopyOnWriteCache is an implementation of Cache interface.

func NewCopyOnWriteCache

func NewCopyOnWriteCache[K comparable, V any]() *CopyOnWriteCache[K, V]

NewCopyOnWriteCache returns a cache implementation interface of Cache interface.

func (*CopyOnWriteCache[K, V]) Delete

func (c *CopyOnWriteCache[K, V]) Delete(del func(key K, val V) bool)

Delete items from cache.

func (*CopyOnWriteCache[K, V]) Get

func (c *CopyOnWriteCache[K, V]) Get(key K) (V, bool)

Get value from cache.

func (*CopyOnWriteCache[K, V]) Set

func (c *CopyOnWriteCache[K, V]) Set(key K, val V)

Set item to cache.

type ExpiryCache

type ExpiryCache[V any] struct {
	Cache[string, ExpiryCacheValue[V]]
}

ExpiryCache is an implementation of Cache interface with cache expiration built in.

func NewExpiryCache

func NewExpiryCache[V any](ctx context.Context, interval time.Duration) *ExpiryCache[V]

NewExpiryCache creates a Cache interface implementation with cleaning (expiration) routine.

type ExpiryCacheValue

type ExpiryCacheValue[V any] struct {
	Val V
	Exp int64
}

ExpiryCacheValue is cache value for expiry cache. Exp represents unix timestamp in seconds.

type Map

type Map[K comparable, V any] map[K]V

Map is a custom map type definition.

Jump to

Keyboard shortcuts

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