Documentation
¶
Overview ¶
Package cache provides caching functionality for flags and API keys.
Index ¶
- type EnvironmentLister
- type FlagCache
- func (c *FlagCache) Get(ctx context.Context, envID, flagKey string) (*domain.FlagConfig, error)
- func (c *FlagCache) GetAPIKey(ctx context.Context, apiKey string) (*repository.APIKeyInfo, error)
- func (c *FlagCache) GetPrivilegedAPIKey(ctx context.Context, apiKey string) (*repository.PrivilegedAPIKeyInfo, error)
- func (c *FlagCache) InvalidateAPIKey(ctx context.Context, apiKey string) error
- func (c *FlagCache) InvalidateAPIKeyByHash(ctx context.Context, keyHash string) error
- func (c *FlagCache) InvalidateEnvironment(ctx context.Context, envID string) error
- func (c *FlagCache) InvalidateFlag(ctx context.Context, envID, flagKey string) error
- func (c *FlagCache) InvalidatePrivilegedAPIKey(ctx context.Context, apiKey string) error
- func (c *FlagCache) InvalidatePrivilegedAPIKeyByHash(ctx context.Context, keyHash string) error
- func (c *FlagCache) InvalidateProject(ctx context.Context, projectID string) error
- func (c *FlagCache) Set(ctx context.Context, envID, flagKey string, config *domain.FlagConfig) error
- func (c *FlagCache) SetAPIKey(ctx context.Context, apiKey string, info *repository.APIKeyInfo) error
- func (c *FlagCache) SetEnvironmentLister(envs EnvironmentLister)
- func (c *FlagCache) SetPrivilegedAPIKey(ctx context.Context, apiKey string, info *repository.PrivilegedAPIKeyInfo) error
- type FlagCacheConfig
- type WebhookCache
- func (c *WebhookCache) BatchGetUsers(ctx context.Context, ids []string, ...) (map[string]*repository.User, error)
- func (c *WebhookCache) DeserializeWebhooks(data []byte) ([]repository.Webhook, error)
- func (c *WebhookCache) GetEnvironment(ctx context.Context, id string, ...) (*repository.Environment, error)
- func (c *WebhookCache) GetProject(ctx context.Context, id string, ...) (*repository.Project, error)
- func (c *WebhookCache) GetUser(ctx context.Context, id string, ...) (*repository.User, error)
- func (c *WebhookCache) GetWebhooksForEvent(ctx context.Context, projectID, eventType string, ...) ([]repository.Webhook, error)
- func (c *WebhookCache) HasRecentEvent(ctx context.Context, eventID string) (bool, error)
- func (c *WebhookCache) InvalidateProject(projectID string)
- func (c *WebhookCache) InvalidateUser(userID string)
- func (c *WebhookCache) InvalidateWebhook(webhookID string)
- func (c *WebhookCache) SerializeWebhooks(webhooks []repository.Webhook) ([]byte, error)
- func (c *WebhookCache) SetRecentEvent(ctx context.Context, eventID string, ttl time.Duration) error
- func (c *WebhookCache) Stats() map[string]int
- type WebhookCacheConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EnvironmentLister ¶
type EnvironmentLister interface {
ListByProject(ctx context.Context, projectID string) ([]repository.Environment, error)
}
EnvironmentLister is an interface for listing environments by project.
type FlagCache ¶
type FlagCache struct {
// contains filtered or unexported fields
}
FlagCache provides caching for flag configurations.
func NewFlagCache ¶
func NewFlagCache(client *redis.Client, config FlagCacheConfig) *FlagCache
NewFlagCache creates a new FlagCache.
func (*FlagCache) GetAPIKey ¶
func (c *FlagCache) GetAPIKey(ctx context.Context, apiKey string) (*repository.APIKeyInfo, error)
GetAPIKey retrieves an API key info from cache.
func (*FlagCache) GetPrivilegedAPIKey ¶
func (c *FlagCache) GetPrivilegedAPIKey(ctx context.Context, apiKey string) (*repository.PrivilegedAPIKeyInfo, error)
GetPrivilegedAPIKey retrieves a privileged API key info from cache.
func (*FlagCache) InvalidateAPIKey ¶
InvalidateAPIKey removes an API key from cache.
func (*FlagCache) InvalidateAPIKeyByHash ¶
InvalidateAPIKeyByHash removes a cached API key by its hash. This is used when revoking a key - the hash is stored in the DB.
func (*FlagCache) InvalidateEnvironment ¶
InvalidateEnvironment removes all flags for an environment from cache.
func (*FlagCache) InvalidateFlag ¶
InvalidateFlag removes a specific flag from cache.
func (*FlagCache) InvalidatePrivilegedAPIKey ¶
InvalidatePrivilegedAPIKey removes a privileged API key from cache.
func (*FlagCache) InvalidatePrivilegedAPIKeyByHash ¶
InvalidatePrivilegedAPIKeyByHash removes a cached privileged API key by its hash.
func (*FlagCache) InvalidateProject ¶
InvalidateProject removes all flags for a project from cache.
func (*FlagCache) Set ¶
func (c *FlagCache) Set(ctx context.Context, envID, flagKey string, config *domain.FlagConfig) error
Set stores a flag config in cache.
func (*FlagCache) SetAPIKey ¶
func (c *FlagCache) SetAPIKey(ctx context.Context, apiKey string, info *repository.APIKeyInfo) error
SetAPIKey stores an API key info in cache.
func (*FlagCache) SetEnvironmentLister ¶
func (c *FlagCache) SetEnvironmentLister(envs EnvironmentLister)
SetEnvironmentLister sets the environment lister for project invalidation.
func (*FlagCache) SetPrivilegedAPIKey ¶
func (c *FlagCache) SetPrivilegedAPIKey(ctx context.Context, apiKey string, info *repository.PrivilegedAPIKeyInfo) error
SetPrivilegedAPIKey stores a privileged API key info in cache.
type FlagCacheConfig ¶
FlagCacheConfig configures the flag cache.
type WebhookCache ¶
type WebhookCache struct {
// contains filtered or unexported fields
}
WebhookCache provides caching for webhook-related data. Uses a combination of Redis for distributed caching and local in-memory cache for frequently accessed data (users, projects, environments).
func NewWebhookCache ¶
func NewWebhookCache(client *redis.Client, config WebhookCacheConfig) *WebhookCache
NewWebhookCache creates a new WebhookCache.
func (*WebhookCache) BatchGetUsers ¶
func (c *WebhookCache) BatchGetUsers(ctx context.Context, ids []string, fetch func(context.Context, []string) (map[string]*repository.User, error)) (map[string]*repository.User, error)
BatchGetUsers retrieves multiple users from cache, fetching missing ones.
func (*WebhookCache) DeserializeWebhooks ¶
func (c *WebhookCache) DeserializeWebhooks(data []byte) ([]repository.Webhook, error)
DeserializeWebhooks deserializes webhooks from Redis.
func (*WebhookCache) GetEnvironment ¶
func (c *WebhookCache) GetEnvironment(ctx context.Context, id string, fetch func(context.Context, string) (*repository.Environment, error)) (*repository.Environment, error)
GetEnvironment retrieves an environment from cache, or fetches and caches it.
func (*WebhookCache) GetProject ¶
func (c *WebhookCache) GetProject(ctx context.Context, id string, fetch func(context.Context, string) (*repository.Project, error)) (*repository.Project, error)
GetProject retrieves a project from cache, or fetches and caches it.
func (*WebhookCache) GetUser ¶
func (c *WebhookCache) GetUser(ctx context.Context, id string, fetch func(context.Context, string) (*repository.User, error)) (*repository.User, error)
GetUser retrieves a user from cache, or fetches and caches it.
func (*WebhookCache) GetWebhooksForEvent ¶
func (c *WebhookCache) GetWebhooksForEvent(ctx context.Context, projectID, eventType string, fetch func(context.Context, string, string) ([]repository.Webhook, error)) ([]repository.Webhook, error)
GetWebhooksForEvent retrieves webhooks for a project+event from cache, or fetches and caches them.
func (*WebhookCache) HasRecentEvent ¶
HasRecentEvent checks if an event was recently processed.
func (*WebhookCache) InvalidateProject ¶
func (c *WebhookCache) InvalidateProject(projectID string)
InvalidateProject invalidates all cached webhooks for a project.
func (*WebhookCache) InvalidateUser ¶
func (c *WebhookCache) InvalidateUser(userID string)
InvalidateUser invalidates a user from cache.
func (*WebhookCache) InvalidateWebhook ¶
func (c *WebhookCache) InvalidateWebhook(webhookID string)
InvalidateWebhook invalidates a specific webhook from cache.
func (*WebhookCache) SerializeWebhooks ¶
func (c *WebhookCache) SerializeWebhooks(webhooks []repository.Webhook) ([]byte, error)
Serialize is used when we need to store in Redis (for distributed caching).
func (*WebhookCache) SetRecentEvent ¶
SetRecentEvents stores recent event IDs for deduplication (optional, uses Redis).
func (*WebhookCache) Stats ¶
func (c *WebhookCache) Stats() map[string]int
Stats returns cache statistics.
type WebhookCacheConfig ¶
type WebhookCacheConfig struct {
UserTTL time.Duration // TTL for user cache (default: 1 minute)
ProjectTTL time.Duration // TTL for project cache (default: 5 minutes)
EnvironmentTTL time.Duration // TTL for environment cache (default: 5 minutes)
WebhookTTL time.Duration // TTL for webhook list cache (default: 30 seconds)
RedisPrefix string // Prefix for Redis keys
}
WebhookCacheConfig configures the webhook cache.
func DefaultWebhookCacheConfig ¶
func DefaultWebhookCacheConfig() WebhookCacheConfig
DefaultWebhookCacheConfig returns the default configuration.