reqctx

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package reqctx provides a context.Context based mechanism to cache data for the duration of a request. A new cache is automatically created for every request handled by the httpserver or every message consumed by the stream package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete[T any](ctx context.Context)

Delete removes the stored value. It does nothing if the context was not wrapped using New or no value of the given type was stored.

func Get

func Get[T any](ctx context.Context) *T

Get returns the stored value for the current request or nil if no value has yet been stored. Nil is also returned if the context was not wrapped using New. The returned value is located based on the requested type (thus, you can't store multiple values of the same type in one request).

func New

func New(ctx context.Context) context.Context

New creates a new request context to hold values for the duration of a single request. The returned context is thread safe.

func Set

func Set[T any](ctx context.Context, value T)

Set stores or updates the stored value. It does nothing if the context was not wrapped using New. The value is located based on the type T, existing values in that request are overwritten.

Types

This section is empty.

Jump to

Keyboard shortcuts

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