cache

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides rate limiting and throttling abstractions for the magic link plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashIdentifier

func HashIdentifier(identifier string) string

HashIdentifier produces an opaque hash of the identifier to avoid storing plaintext emails in cache keys.

Types

type Limiter

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

Limiter is a cache-backed rate limiter implementation.

func NewLimiter

func NewLimiter(c corecache.Cache, now func() time.Time) *Limiter

NewLimiter creates a new Limiter backed by an optional cache.

func (*Limiter) CheckAndSetCooldown

func (l *Limiter) CheckAndSetCooldown(ctx context.Context, email string, cooldown time.Duration) (bool, error)

CheckAndSetCooldown checks and activates cooldown for the identifier.

func (*Limiter) CheckRateLimit

func (l *Limiter) CheckRateLimit(ctx context.Context, email string, maxRequests int, window time.Duration) (bool, error)

CheckRateLimit checks whether requests within the given window exceeded maxRequests.

type RateLimiter

type RateLimiter interface {
	// CheckRateLimit verifies if an email is permitted to request a magic link.
	// Returns true if allowed, false if rate limited.
	CheckRateLimit(ctx context.Context, email string, maxRequests int, window time.Duration) (bool, error)

	// CheckAndSetCooldown verifies if cooldown is active, and if not sets it.
	// Returns true if allowed, false if cooldown is active.
	CheckAndSetCooldown(ctx context.Context, email string, cooldown time.Duration) (bool, error)
}

RateLimiter enforces rate limiting and cooldown rules for magic link requests.

Jump to

Keyboard shortcuts

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