cache

package
v3.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cache memoizes the outcome of verifying a credential. A sync client presents the same secret on every request, which otherwise costs a database or identity provider lookup every time. It does not matter what the credential is: an app password, a username and password, a public link token or a signed JWT all go through the same cache. Rejections are cached too, so a client that keeps retrying a stale password is also answered from memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(parts ...string) string

Key hashes the parts, so no secret is held in memory in the clear.

Types

type Cache

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

Cache is safe for concurrent use.

func New

func New(c Config) *Cache

New applies the defaults to the zero fields of c. A negative TTL disables the cache: it then stores nothing and never reports a hit.

func (*Cache) Get

func (c *Cache) Get(key string) (*Identity, error, bool)

Get returns the identity, the error that rejected the credential, and whether the key was cached at all.

func (*Cache) Set

func (c *Cache) Set(key string, id *Identity, err error, notAfter time.Time)

Set stores an identity when err is nil, the rejection otherwise. notAfter, when it is not the zero time, caps the lifetime of the entry, so a cached identity never outlives the credential or the token it describes.

type Config

type Config struct {
	Size        int `mapstructure:"cache_size" docs:"50000;Maximum number of authentication outcomes kept in memory."`
	TTL         int `` /* 184-byte string literal not displayed */
	NegativeTTL int `mapstructure:"negative_cache_ttl" docs:"30;Seconds a rejected credential stays cached."`
}

Embed Config in a service configuration with `mapstructure:",squash"`.

type Identity

type Identity struct {
	User   *userpb.User
	Scopes map[string]*authpb.Scope
	Token  string
}

Token is set only where one was minted for the credential.

Jump to

Keyboard shortcuts

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