Help us shape the future of Go! Take the 2026 Go Developer Survey

memorystore

package
v0.86.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KV

type KV struct {
	// contains filtered or unexported fields
}

KV is a simple in-memory key-value store with TTL support. It is only safe for single-process deployments.

func NewKV

func NewKV() *KV

func (*KV) Consume

func (k *KV) Consume(ctx context.Context, key string) ([]byte, bool, error)

Consume atomically returns and deletes a key under a single lock hold, so a value is delivered to AT MOST ONE caller even under concurrent reads — the in-memory analogue of Redis GETDEL. Required for single-use credentials whose KEY is the secret (passkey challenge, password-reset token); a Get+Del pair would let two concurrent requests both observe the value before either deletes. Missing or expired key => (nil, false, nil).

func (*KV) Del

func (k *KV) Del(ctx context.Context, key string) error

func (*KV) Get

func (k *KV) Get(ctx context.Context, key string) ([]byte, bool, error)

func (*KV) Set

func (k *KV) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

type SIWSCache

type SIWSCache struct {
	// contains filtered or unexported fields
}

SIWSCache stores pending SIWS challenges in memory. This is only suitable for single-node deployments or local development.

func NewSIWSCache

func NewSIWSCache(ttl time.Duration) *SIWSCache

NewSIWSCache creates a new in-memory SIWS challenge cache.

func (*SIWSCache) Close

func (c *SIWSCache) Close() error

Close stops the background cleanup goroutine. Should be called when the cache is no longer needed.

func (*SIWSCache) Consume

func (c *SIWSCache) Consume(ctx context.Context, nonce string) (siws.ChallengeData, bool, error)

Consume atomically retrieves and deletes a challenge (single-use). The write lock makes get+delete a single-winner operation, so two concurrent callers presenting the same nonce can't both verify — closing the SIWS replay window.

func (*SIWSCache) Del

func (c *SIWSCache) Del(ctx context.Context, nonce string) error

Del removes a challenge from memory.

func (*SIWSCache) Get

func (c *SIWSCache) Get(ctx context.Context, nonce string) (siws.ChallengeData, bool, error)

Get retrieves a challenge from memory.

func (*SIWSCache) Put

func (c *SIWSCache) Put(ctx context.Context, nonce string, data siws.ChallengeData) error

Put stores a challenge in memory.

type StateCache

type StateCache struct {
	// contains filtered or unexported fields
}

StateCache is an in-memory implementation of oidckit.StateCache with TTL.

func NewStateCache

func NewStateCache(ttl time.Duration) *StateCache

NewStateCache creates a new in-memory state cache with the given TTL. If ttl <= 0, a default of 10 minutes is used. Starts a background goroutine to clean up expired entries every minute.

func (*StateCache) Close

func (s *StateCache) Close() error

Close stops the background cleanup goroutine. Should be called when the cache is no longer needed.

func (*StateCache) Consume

func (s *StateCache) Consume(ctx context.Context, state string) (oidckit.StateData, bool, error)

Consume atomically returns and deletes the state in one locked step, closing the replay/TOCTOU window a separate Get+Del leaves open. ok=false if the state is absent, expired, or already consumed.

func (*StateCache) Del

func (s *StateCache) Del(ctx context.Context, state string) error

func (*StateCache) Get

func (s *StateCache) Get(ctx context.Context, state string) (oidckit.StateData, bool, error)

func (*StateCache) Put

func (s *StateCache) Put(ctx context.Context, state string, v oidckit.StateData) error

Jump to

Keyboard shortcuts

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