spike

package
v0.0.0-...-28ca4d1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package spike provides a primitive to handle spike-like load on retrieving external resources

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler[T any] struct {
	Fetch func(ctx context.Context, k string) (T, error)
	Set   func(k string, v T)
	Get   func(k string) (T, bool)
}

type Manager

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

func NewCustomManager

func NewCustomManager[T any](h Handler[T]) *Manager[T]

NewCustomManager creates a new Manager with a custom cache implementation controlled by client code it should be used for non-trivial flows or non-default cache implementations

func NewManager

func NewManager[T any](fetch func(ctx context.Context, k string) (T, error), cacheTime time.Duration) *Manager[T]

NewManager creates a new Manager with a default cache implementation it is preferred way of creating a new Manager

func (*Manager[T]) GetResult

func (m *Manager[T]) GetResult(ctx context.Context, k string) (T, error)

Jump to

Keyboard shortcuts

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