cache

package
v0.0.0-...-6b3b694 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("cache entry not found")

Functions

This section is empty.

Types

type Set

type Set[T any] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T any](prefix string) *Set[T]

func (*Set[T]) Delete

func (c *Set[T]) Delete(key string) error

func (*Set[T]) Flush

func (c *Set[T]) Flush() error

func (*Set[T]) Get

func (c *Set[T]) Get(key string, dest *T) error

func (*Set[T]) MutexGetSet

func (c *Set[T]) MutexGetSet(key string, dest *T, valueFunc func() (*T, error), expire time.Duration) (bool, error)

MutexGetSet gets value from cache and writes to dest, or if the key does not exist, it executes valueFunc to get cache value if the key still not exists when serially dispatched, sets value to cache and writes value to dest. The first return value means whether the value is got from cache or not. True means calculated; False means got from cache.

func (*Set[T]) Set

func (c *Set[T]) Set(key string, value T, expire time.Duration)

type Singular

type Singular[T any] struct {
	// contains filtered or unexported fields
}

func NewSingular

func NewSingular[T any](key string) *Singular[T]

func (*Singular[T]) Delete

func (c *Singular[T]) Delete() error

func (*Singular[T]) Get

func (c *Singular[T]) Get(dest *T) error

func (*Singular[T]) MutexGetSet

func (c *Singular[T]) MutexGetSet(dest *T, valueFunc func() (T, error), expire time.Duration) error

MutexGetSet gets value from cache and writes to dest, or if the key does not exist, it executes valueFunc to get cache value if the key still not exists when serially dispatched, sets value to cache and writes value to dest. The first return value means whether the value is got from cache or not. True means calculated; False means got from cache.

func (*Singular[T]) Set

func (c *Singular[T]) Set(value T, expire time.Duration)

Jump to

Keyboard shortcuts

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