cache

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 1 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 Cacheable[K]] struct {
	// contains filtered or unexported fields
}

Cache is a goroutine safe write-through cache with generics type.

func NewCache

func NewCache[K comparable, V Cacheable[K]](read func(K) (V, error), write func(V) error) *Cache[K, V]

NewCache creates a new Cache.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (*V, error)

Get returns a value from the cache.

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V) error

Set sets a value to the cache.

type Cacheable

type Cacheable[K comparable] interface {
	CacheKey() K
}

Jump to

Keyboard shortcuts

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