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

cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCacheKey

func CreateCacheKey(appIdentifier string, installationID int64) string

CreateCacheKey creates a cache key for a specific app configuration. The appIdentifier may be a numeric App ID string or a Client ID.

Types

type CacheStats

type CacheStats struct {
	TotalTokens   int
	ValidTokens   int
	ExpiredTokens int
}

CacheStats contains cache statistics

type CachedToken

type CachedToken struct {
	Token     string    // GitHub installation token (ghs_...)
	ExpiresAt time.Time // When this token expires (55-min from creation)
	CreatedAt time.Time // When this token was cached
}

CachedToken represents a cached GitHub App installation token with expiration information.

Installation tokens (not JWTs) are cached because: - JWT tokens are short-lived (~10min) and cheap to generate - Installation tokens require API calls to GitHub and have 1-hour validity - Caching reduces GitHub API load and improves performance

type TokenCache

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

TokenCache provides thread-safe caching of GitHub App installation tokens with TTL.

SECURITY NOTE: This cache stores installation tokens IN MEMORY ONLY. Tokens are NOT persisted to disk or encrypted storage. This design prioritizes security over convenience - tokens expire with process lifetime, reducing attack surface.

Installation tokens have 1-hour validity from GitHub and are cached for 55 minutes (5-minute safety buffer). This reduces API calls to GitHub by ~98% while ensuring tokens are never stale.

For detailed security analysis, see docs/TOKEN_CACHING.md

func NewTokenCache

func NewTokenCache() *TokenCache

NewTokenCache creates a new token cache.

func (*TokenCache) Clear

func (c *TokenCache) Clear()

Clear removes all tokens from the cache

func (*TokenCache) Delete

func (c *TokenCache) Delete(key string)

Delete removes a token from the cache

func (*TokenCache) Get

func (c *TokenCache) Get(key string) (string, bool)

Get retrieves a token from the cache if it exists and is not expired

func (*TokenCache) GetStats

func (c *TokenCache) GetStats() CacheStats

GetStats returns cache statistics

func (*TokenCache) Set

func (c *TokenCache) Set(key, token string, ttl time.Duration)

Set stores a token in the cache with the specified TTL

func (*TokenCache) Size

func (c *TokenCache) Size() int

Size returns the number of cached tokens

Jump to

Keyboard shortcuts

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