cache

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: MIT Imports: 4 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[V any] struct {
	Cache map[string]V
	Mutex *sync.Mutex
}

Cache - generic cache implementation

func NewCache

func NewCache[V any]() *Cache[V]

NewCache - create new cache with generic type V

func (*Cache[V]) Get

func (c *Cache[V]) Get(key string) (V, bool)

Get - fetch value from cache by key

func (*Cache[V]) Put

func (c *Cache[V]) Put(key string, value V)

Put - put value into cache by key

type ExpiringCache

type ExpiringCache[V any] struct {
	Cache map[string]ExpiringItem[V]
	Mutex *sync.Mutex
}

ExpiringCache - cache with items with expiration time

func NewExpiringCache

func NewExpiringCache[V any]() *ExpiringCache[V]

NewExpiringCache - create new cache with generic type V

func (*ExpiringCache[V]) Get

func (c *ExpiringCache[V]) Get(key string) (V, bool)

Get - fetch value from cache by key

func (*ExpiringCache[V]) Put

func (c *ExpiringCache[V]) Put(key string, value V, expiration time.Time)

Put - put value into cache by key

type ExpiringItem

type ExpiringItem[V any] struct {
	Value      V
	Expiration time.Time
}

ExpiringItem - item with expiration time

Jump to

Keyboard shortcuts

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