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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyNormalized

func KeyNormalized(norm string) string

KeyNormalized returns the namespaced cache key for a normalized username. Format: gomodularauth:username:norm:<normalized>

func KeyUserID

func KeyUserID(userID string) string

KeyUserID returns the namespaced cache key for a Core user ID. Format: gomodularauth:username:user:<userID>

Types

type Cache

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

Cache wraps the core Cache adapter with semantic username operations.

func New

func New(c corecache.Cache, ttl time.Duration) *Cache

New constructs a semantic Cache wrapper around an optional core Cache. If c is nil, Cache gracefully acts as a no-op layer.

func (*Cache) GetByNormalized

func (c *Cache) GetByNormalized(ctx context.Context, norm string) (*CachedRecord, bool)

GetByNormalized returns the cached username record for a normalized username, if present.

func (*Cache) GetByUserID

func (c *Cache) GetByUserID(ctx context.Context, userID string) (*CachedRecord, bool)

GetByUserID returns the cached username record for a user ID, if present.

func (*Cache) Invalidate

func (c *Cache) Invalidate(ctx context.Context, norm, userID string)

Invalidate removes cached entries for the normalized username and user ID.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, rec *CachedRecord)

Set stores the record in both normalized and user ID cache entries.

type CachedRecord

type CachedRecord struct {
	UserID     string    `json:"user_id"`
	Username   string    `json:"username"`
	Normalized string    `json:"normalized"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

CachedRecord is the cached representation of a username mapping.

Jump to

Keyboard shortcuts

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