store

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package defines Store interface for cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStore

type MemoryStore[V any] struct {
	// contains filtered or unexported fields
}

A cache store that stores cached values in memory.

Thanks to sync.Map, this cache store is safe for concurrent use by multiple goroutines.

func NewMemoryStore

func NewMemoryStore[V any]() *MemoryStore[V]

Create a MemoryStore.

func (*MemoryStore[V]) Get

func (cs *MemoryStore[V]) Get(ctx context.Context, key string) (Value[V], error)

Get a cached value with a key.

func (*MemoryStore[V]) Set

func (cs *MemoryStore[V]) Set(ctx context.Context, key string, value V) error

Store a value with a key.

type Store

type Store[K, V any] interface {
	// Get a cached value with a key.
	// The returned value needs to be wraped with Value that represents hit or miss.
	Get(ctx context.Context, key K) (value Value[V], err error)

	// Store a value with a key.
	Set(ctx context.Context, key K, value V) (err error)
}

An interface that defines the behavior of a key-value cache store.

type Value

type Value[V any] *V

A type that represents a cache hit with a cached value or a cache miss.

func Hit

func Hit[V any](v V) Value[V]

A Value that represents an existing cached value in a cache store.

func Miss

func Miss[V any]() Value[V]

A Value that represents a cache miss.

Jump to

Keyboard shortcuts

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