Documentation
¶
Overview ¶
Package cache contains tenant-aware cache abstractions.
Index ¶
- Variables
- type Cache
- type KeyBuilder
- type Memory
- type Option
- type Redis
- func (cache *Redis) Close() error
- func (cache *Redis) Delete(ctx context.Context, key string) error
- func (cache *Redis) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (cache *Redis) Ping(ctx context.Context) error
- func (cache *Redis) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- type RedisClient
- type RedisPinger
- type TenantCache
Constants ¶
This section is empty.
Variables ¶
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") // ErrInvalidRedisConfig reports an invalid Redis cache adapter configuration. ErrInvalidRedisConfig = errors.New("gotenancy/cache: invalid redis config") )
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 Redis ¶ added in v0.1.7
type Redis struct {
// contains filtered or unexported fields
}
Redis stores cache values in Redis through a go-redis client.
func NewRedis ¶ added in v0.1.7
func NewRedis(client RedisClient) (*Redis, error)
NewRedis creates a cache adapter from an existing go-redis client.
The caller owns the client configuration. Close closes the provided client.
func NewRedisFromClusterOptions ¶ added in v0.1.7
func NewRedisFromClusterOptions(options *redis.ClusterOptions) (*Redis, error)
NewRedisFromClusterOptions creates a Redis cache adapter from cluster client options.
func NewRedisFromOptions ¶ added in v0.1.7
NewRedisFromOptions creates a Redis cache adapter from standalone client options.
func NewRedisFromURL ¶ added in v0.1.7
NewRedisFromURL creates a Redis cache adapter from a redis:// or rediss:// URL.
type RedisClient ¶ added in v0.1.7
type RedisClient interface {
Get(ctx context.Context, key string) *redis.StringCmd
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
Del(ctx context.Context, keys ...string) *redis.IntCmd
Close() error
}
RedisClient is the subset of go-redis used by the cache adapter.
type RedisPinger ¶ added in v0.1.7
RedisPinger is implemented by go-redis clients that support PING health checks.
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.