request

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCacheTTL               = 1 * time.Minute
	DefaultCacheTokenMaxTries int = 10
	DefaultCacheTokenLen      int = 8
	DefaultCacheMaxInFlight   int = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[E any] interface {
	// Insert creates a new unique token for the request object and returns it. If it's not possible to generate
	// a unique token, an error is returned.
	Insert(req E) (token string, err error)
	// Consume looks up the cache for the request associated with the given token and returns it if found.
	// If the token is unknown or expired, no request & found = false is returned.
	Consume(token string) (req E, found bool)
}

Cache associates requests of type E with request tokens. This allows requests to be approved and later on be picked up with their associated token.

func NewCache

func NewCache[E any](opts ...func(*CacheOptions)) Cache[E]

NewCache constructs a new Cache that tracks request tokens with requests of type E.

type CacheOptions

type CacheOptions struct {
	TTL           time.Duration
	MaxInFlight   int
	TokenMaxTries int
	TokenLen      int
}

Jump to

Keyboard shortcuts

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