Documentation
¶
Index ¶
- Variables
- func AuthorizationError(detail string, args ...any) error
- func DoesNotExistError(detail string, args ...any) error
- func DuplicateEntryError(detail string, args ...any) error
- func Error(err error, detail string, args ...any) error
- func InvalidArgument(detail string, args ...any) error
- func IsError(err error, target error) bool
- func Must(err error)
- func MustReturn[T any](value T, err error) T
- func TooManyRequests(detail string, args ...any) error
- type AtomicReference
- type CacheStore
- type Clock
- type Entry
- type EntryState
- type LoadingCache
- func (cache *LoadingCache[V]) Cancel(key string)
- func (cache *LoadingCache[V]) Check(key string) bool
- func (cache *LoadingCache[V]) Drop(key string)
- func (cache *LoadingCache[V]) Get(key string) Value[V]
- func (cache *LoadingCache[V]) Put(key string, loadingFunc func() (V, error)) error
- func (cache *LoadingCache[V]) Refresh(key string) error
- func (cache *LoadingCache[V]) Replace(key string, loadingFunc func() (V, error))
- type MapStore
- type StableClock
- type TreeStore
- type Value
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AuthorizationError ¶
func DoesNotExistError ¶
func DuplicateEntryError ¶
func InvalidArgument ¶
func MustReturn ¶
func TooManyRequests ¶
Types ¶
type AtomicReference ¶
type AtomicReference[T any] struct { // contains filtered or unexported fields }
AtomicReference is a Generic wrapper for atomic.Value
func NewAtomicReference ¶
func NewAtomicReference[T any](init T) *AtomicReference[T]
NewAtomicReference returns a new AtomicReference with an initial value.
func (*AtomicReference[T]) Store ¶
func (ref *AtomicReference[T]) Store(value T)
Store wraps atomic.Store
func (*AtomicReference[T]) Swap ¶
func (ref *AtomicReference[T]) Swap(value T) T
Swap wraps atomic.Swap
type CacheStore ¶
type Clock ¶
type Entry ¶
type Entry[V any] struct { // contains filtered or unexported fields }
Entry represents a cached entry.
type EntryState ¶
type EntryState uint8
EntryState represents the current state of a CacheEntry.
const ( // EntryInit marks a cache entry as initialized but not yet populated. EntryInit EntryState = iota // EntryPending indicates the cache entry is the process of being updated. EntryPending // EntryError indicates the last attempt to update a cache entry failed. EntryError // EntryCanceled indicates an update was attempted but canceled before completing. EntryCanceled // EntryReady indicates the cache entry is ready for use. EntryReady )
func (EntryState) String ¶
func (state EntryState) String() string
String returns EntryState as a string.
type LoadingCache ¶
type LoadingCache[V any] struct { // contains filtered or unexported fields }
LoadingCache is an in-memory key-value store. Value lifecycles are managed by the cache until their key is dropped.
func NewLoadingCache ¶
func NewLoadingCache[V any](store CacheStore[V]) *LoadingCache[V]
NewLoadingCache returns a new instance of LoadingCache[V].
func (*LoadingCache[V]) Cancel ¶
func (cache *LoadingCache[V]) Cancel(key string)
Cancel cancels an update and notifies all watchers.
func (*LoadingCache[V]) Drop ¶
func (cache *LoadingCache[V]) Drop(key string)
Drop removes the entry associated with key from the cache.
func (*LoadingCache[V]) Get ¶
Get the Entry associated with Key, loading a new instance if unknown. If Entry exists and is EntryPending this call parks the caller until the update is complete.
func (*LoadingCache[V]) Put ¶
Put creates a new entry in the LoadingCache using the supplied loadingFunc. All entries are loaded lazily meaning loadingFunc is not invoked until LoadingCache.Get(key) is called.
type MapStore ¶
type MapStore[V any] struct { // contains filtered or unexported fields }
func NewMapStore ¶
type StableClock ¶
type StableClock interface { Clock // Tick increments StableTime by duration Tick(duration time.Duration) }
func StableTime ¶
func StableTime(epoch time.Time) StableClock
StableTime is a clock which must be manually updated.
type TreeStore ¶
type TreeStore[V any] struct { // contains filtered or unexported fields }
func NewTreeStore ¶
type Value ¶
type Value[V any] struct { State EntryState Value V Error error }
Value is an immutable snapshot of a CacheEntry's state.