Documentation
¶
Index ¶
- func TenantKeyPrefix(ctx context.Context, globalNamespace, secureMode bool) (string, error)
- type Cache
- func GetCache[K comparable, V any](manager Manager, name string, keyFunc func(K) string) (Cache[K, V], bool)
- func NewGenericCache[K comparable, V any](raw RawCache, keyFunc func(K) string) Cache[K, V]
- func NewTenantAwareCache[K comparable, V any](raw RawCache, keyFunc func(K) string, opts ...TenantCacheOption) Cache[K, V]
- type GenericCache
- func (g *GenericCache[K, V]) Close() error
- func (g *GenericCache[K, V]) Delete(ctx context.Context, key K) error
- func (g *GenericCache[K, V]) Exists(ctx context.Context, key K) (bool, error)
- func (g *GenericCache[K, V]) Flush(ctx context.Context) error
- func (g *GenericCache[K, V]) Get(ctx context.Context, key K) (V, bool, error)
- func (g *GenericCache[K, V]) Set(ctx context.Context, key K, value V, ttl time.Duration) error
- type InMemoryCache
- func (c *InMemoryCache) Close() error
- func (c *InMemoryCache) Decrement(ctx context.Context, key string, delta int64) (int64, error)
- func (c *InMemoryCache) Delete(_ context.Context, key string) error
- func (c *InMemoryCache) Exists(_ context.Context, key string) (bool, error)
- func (c *InMemoryCache) Expire(_ context.Context, key string, ttl time.Duration) error
- func (c *InMemoryCache) Flush(_ context.Context) error
- func (c *InMemoryCache) Get(_ context.Context, key string) ([]byte, bool, error)
- func (c *InMemoryCache) Increment(_ context.Context, key string, delta int64) (int64, error)
- func (c *InMemoryCache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error
- func (c *InMemoryCache) SupportsPerKeyTTL() bool
- type Manager
- type Option
- type Options
- type RawCache
- type TenantAwareRaw
- func (t *TenantAwareRaw) Close() error
- func (t *TenantAwareRaw) Decrement(ctx context.Context, key string, delta int64) (int64, error)
- func (t *TenantAwareRaw) Delete(ctx context.Context, key string) error
- func (t *TenantAwareRaw) Exists(ctx context.Context, key string) (bool, error)
- func (t *TenantAwareRaw) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (t *TenantAwareRaw) Flush(ctx context.Context) error
- func (t *TenantAwareRaw) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (t *TenantAwareRaw) Increment(ctx context.Context, key string, delta int64) (int64, error)
- func (t *TenantAwareRaw) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (t *TenantAwareRaw) SupportsPerKeyTTL() bool
- type TenantCacheOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TenantKeyPrefix ¶ added in v2.0.14
TenantKeyPrefix returns the cache key namespace for ctx per Secure Profile rules (K25/K31):
g/ — explicit WithGlobalNamespace on the cache instance (caller sets) t/id/ — bindable TenantID from Claims or scoped SystemPrincipal sys/s/ — SystemPrincipal without TenantID unset/ — FailOpen missing claims
globalNamespace=true forces g/.
Types ¶
type Cache ¶
type Cache[K comparable, V any] interface { // Get retrieves an item from the cache Get(ctx context.Context, key K) (V, bool, error) // Set sets an item in the cache with the specified TTL Set(ctx context.Context, key K, value V, ttl time.Duration) error // Delete removes an item from the cache Delete(ctx context.Context, key K) error // Exists checks if a key exists in the cache Exists(ctx context.Context, key K) (bool, error) // Flush clears all items from the cache Flush(ctx context.Context) error // Close releases any resources used by the cache Close() error }
Cache is a generic cache interface with automatic serialization.
func GetCache ¶
func GetCache[K comparable, V any]( manager Manager, name string, keyFunc func(K) string, ) (Cache[K, V], bool)
GetCache returns a typed cache with automatic serialization.
func NewGenericCache ¶
func NewGenericCache[K comparable, V any](raw RawCache, keyFunc func(K) string) Cache[K, V]
NewGenericCache creates a new generic cache with automatic serialization.
func NewTenantAwareCache ¶ added in v2.0.14
func NewTenantAwareCache[K comparable, V any]( raw RawCache, keyFunc func(K) string, opts ...TenantCacheOption, ) Cache[K, V]
NewTenantAwareCache builds a generic cache with tenant key prefixes.
type GenericCache ¶
type GenericCache[K comparable, V any] struct { // contains filtered or unexported fields }
GenericCache wraps a RawCache and provides automatic serialization.
func (*GenericCache[K, V]) Close ¶
func (g *GenericCache[K, V]) Close() error
func (*GenericCache[K, V]) Delete ¶
func (g *GenericCache[K, V]) Delete(ctx context.Context, key K) error
func (*GenericCache[K, V]) Exists ¶
func (g *GenericCache[K, V]) Exists(ctx context.Context, key K) (bool, error)
type InMemoryCache ¶
type InMemoryCache struct {
// contains filtered or unexported fields
}
InMemoryCache is a thread-safe in-memory cache implementation.
func (*InMemoryCache) Close ¶
func (c *InMemoryCache) Close() error
Close stops the cleanup goroutine and releases resources.
func (*InMemoryCache) Delete ¶
func (c *InMemoryCache) Delete(_ context.Context, key string) error
Delete removes an item from the cache.
func (*InMemoryCache) Flush ¶
func (c *InMemoryCache) Flush(_ context.Context) error
Flush clears all items from the cache.
func (*InMemoryCache) SupportsPerKeyTTL ¶
func (c *InMemoryCache) SupportsPerKeyTTL() bool
type Manager ¶
type Option ¶
type Option func(*Options)
Option configures database connection settings.
func WithCredsFile ¶
func WithMaxAge ¶
WithMaxAge returns an Option to configure the max age of the cache.
type RawCache ¶
type RawCache interface {
Get(ctx context.Context, key string) ([]byte, bool, error)
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Expire(ctx context.Context, key string, ttl time.Duration) error
SupportsPerKeyTTL() bool
Delete(ctx context.Context, key string) error
Exists(ctx context.Context, key string) (bool, error)
Flush(ctx context.Context) error
Close() error
Increment(ctx context.Context, key string, delta int64) (int64, error)
Decrement(ctx context.Context, key string, delta int64) (int64, error)
}
RawCache is the low-level cache interface that works with bytes.
func NewInMemoryCache ¶
func NewInMemoryCache() RawCache
NewInMemoryCache creates a new in-memory cache.
type TenantAwareRaw ¶ added in v2.0.14
type TenantAwareRaw struct {
// contains filtered or unexported fields
}
TenantAwareRaw wraps RawCache with automatic tenant key prefixes.
func NewTenantAwareRaw ¶ added in v2.0.14
func NewTenantAwareRaw(raw RawCache, opts ...TenantCacheOption) *TenantAwareRaw
NewTenantAwareRaw wraps raw with tenant prefixes. Prefix is off only when this wrapper is not used — call sites opt in via NewTenantAwareRaw.
func (*TenantAwareRaw) Close ¶ added in v2.0.14
func (t *TenantAwareRaw) Close() error
func (*TenantAwareRaw) Delete ¶ added in v2.0.14
func (t *TenantAwareRaw) Delete(ctx context.Context, key string) error
func (*TenantAwareRaw) Flush ¶ added in v2.0.14
func (t *TenantAwareRaw) Flush(ctx context.Context) error
func (*TenantAwareRaw) SupportsPerKeyTTL ¶ added in v2.0.14
func (t *TenantAwareRaw) SupportsPerKeyTTL() bool
type TenantCacheOption ¶ added in v2.0.14
type TenantCacheOption func(*tenantCacheConfig)
TenantCacheOption configures a tenant-aware cache wrapper.
func WithGlobalNamespace ¶ added in v2.0.14
func WithGlobalNamespace() TenantCacheOption
WithGlobalNamespace forces the g/ prefix for shared lookups (JWKS, flags).
func WithSecureCacheMode ¶ added in v2.0.14
func WithSecureCacheMode(secure bool) TenantCacheOption
WithSecureCacheMode refuses cache ops without a bindable tenant (Secure Profile). Default false uses unset/ when claims are missing.