Documentation
¶
Overview ¶
Package cache contains tenant-aware cache abstractions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNoTenant reports cache access without tenant or allowed host context. ErrNoTenant = gotenancy.ErrNoTenant // ErrUnsafeKey reports a key that attempts to bypass tenant scoping. ErrUnsafeKey = errors.New("gotenancy/cache: unsafe key") // ErrHostGlobalKeyNotAllowed reports host global key access without explicit opt-in. ErrHostGlobalKeyNotAllowed = errors.New("gotenancy/cache: host global key not allowed") // ErrInvalidCacheSize reports an invalid bounded memory cache size. ErrInvalidCacheSize = errors.New("gotenancy/cache: invalid cache size") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
Get(ctx context.Context, key string) ([]byte, bool, error)
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Delete(ctx context.Context, key string) error
}
Cache stores byte values.
type KeyBuilder ¶
type KeyBuilder struct {
AllowHostGlobal bool
}
KeyBuilder creates scoped cache keys.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a thread-safe in-memory cache.
func NewBoundedMemory ¶
NewBoundedMemory creates a memory cache with a maximum number of entries.
type Option ¶
type Option func(*TenantCache)
Option configures TenantCache.
func WithHostGlobalKeys ¶
WithHostGlobalKeys allows host context to access global cache keys.
type TenantCache ¶
type TenantCache struct {
// contains filtered or unexported fields
}
TenantCache scopes all cache keys by tenant or explicitly allowed host global keys.
func NewTenantCache ¶
func NewTenantCache(next Cache, opts ...Option) *TenantCache
NewTenantCache creates a scoped cache wrapper.
func (*TenantCache) Delete ¶
func (cache *TenantCache) Delete(ctx context.Context, key string) error
Delete removes a scoped cache key.
Click to show internal directories.
Click to hide internal directories.