cache

package
v0.0.0-...-7a9cc58 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cache provides caching functionality for flags and API keys.

Index

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) Get

func (c *FlagCache) Get(ctx context.Context, envID, flagKey string) (*domain.FlagConfig, error)

Get retrieves a flag config from cache.

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

func (c *FlagCache) InvalidateAPIKey(ctx context.Context, apiKey string) error

InvalidateAPIKey removes an API key from cache.

func (*FlagCache) InvalidateAPIKeyByHash

func (c *FlagCache) InvalidateAPIKeyByHash(ctx context.Context, keyHash string) error

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

func (c *FlagCache) InvalidateEnvironment(ctx context.Context, envID string) error

InvalidateEnvironment removes all flags for an environment from cache.

func (*FlagCache) InvalidateFlag

func (c *FlagCache) InvalidateFlag(ctx context.Context, envID, flagKey string) error

InvalidateFlag removes a specific flag from cache.

func (*FlagCache) InvalidatePrivilegedAPIKey

func (c *FlagCache) InvalidatePrivilegedAPIKey(ctx context.Context, apiKey string) error

InvalidatePrivilegedAPIKey removes a privileged API key from cache.

func (*FlagCache) InvalidatePrivilegedAPIKeyByHash

func (c *FlagCache) InvalidatePrivilegedAPIKeyByHash(ctx context.Context, keyHash string) error

InvalidatePrivilegedAPIKeyByHash removes a cached privileged API key by its hash.

func (*FlagCache) InvalidateProject

func (c *FlagCache) InvalidateProject(ctx context.Context, projectID string) error

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

type FlagCacheConfig struct {
	TTL    time.Duration
	Prefix string
}

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

func (c *WebhookCache) HasRecentEvent(ctx context.Context, eventID string) (bool, error)

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

func (c *WebhookCache) SetRecentEvent(ctx context.Context, eventID string, ttl time.Duration) error

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.

Jump to

Keyboard shortcuts

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