cache

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoalCache

type GoalCache interface {
	// GetGoalByID retrieves a goal by its unique ID.
	// Returns nil if goal does not exist.
	// Time complexity: O(1)
	GetGoalByID(goalID string) *domain.Goal

	// GetGoalsByStatCode retrieves all goals that track a specific stat code.
	// Multiple goals can track the same stat (e.g., multiple challenges tracking "login_count").
	// Returns empty slice if no goals track this stat.
	// Time complexity: O(1)
	GetGoalsByStatCode(statCode string) []*domain.Goal

	// GetChallengeByChallengeID retrieves a challenge by its unique ID.
	// Returns nil if challenge does not exist.
	// Time complexity: O(1)
	GetChallengeByChallengeID(challengeID string) *domain.Challenge

	// GetAllChallenges retrieves all configured challenges.
	// Returns all challenges in the order they appear in the config file.
	// Time complexity: O(1)
	GetAllChallenges() []*domain.Challenge

	// GetAllGoals retrieves all configured goals across all challenges.
	// Useful for filtering goals by properties like event_source.
	// Returns all goals flattened from all challenges.
	// Time complexity: O(n) where n is total number of goals
	GetAllGoals() []*domain.Goal

	// M3: GetGoalsWithDefaultAssigned retrieves all goals that have default_assigned = true.
	// Used by initialization endpoint to determine which goals to assign to new players.
	// Returns empty slice if no goals are marked as default assigned.
	// Time complexity: O(n) where n is total number of goals
	GetGoalsWithDefaultAssigned() []*domain.Goal

	// Reload reloads the cache from the config file.
	// In M1, this requires application restart (config is baked into Docker image).
	// Returns error if config file cannot be read or is invalid.
	Reload() error
}

GoalCache provides O(1) in-memory lookups for goal configurations. This cache is built at application startup from the challenges.json config file. All lookups are read-only and thread-safe.

type InMemoryGoalCache

type InMemoryGoalCache struct {
	// contains filtered or unexported fields
}

InMemoryGoalCache provides O(1) in-memory lookups for goal configurations. All maps are built at startup and provide thread-safe read access. This cache is immutable after construction (reload requires application restart in M1).

func NewInMemoryGoalCache

func NewInMemoryGoalCache(cfg *config.Config, configPath string, logger *slog.Logger) *InMemoryGoalCache

NewInMemoryGoalCache creates a new cache from the provided configuration. The cache is immediately built and ready for lookups.

Parameters:

  • cfg: Validated configuration containing challenges and goals
  • configPath: Path to config file (used for reload operation)
  • logger: Structured logger for operational logging

Returns:

  • *InMemoryGoalCache: Ready-to-use cache with all indexes built

func (*InMemoryGoalCache) GetAllChallenges

func (c *InMemoryGoalCache) GetAllChallenges() []*domain.Challenge

GetAllChallenges retrieves all configured challenges. Returns all challenges in the order they appear in the config file. Time complexity: O(1)

func (*InMemoryGoalCache) GetAllGoals

func (c *InMemoryGoalCache) GetAllGoals() []*domain.Goal

GetAllGoals retrieves all configured goals across all challenges. This is useful for filtering goals by properties like event_source. Returns all goals flattened from all challenges. Time complexity: O(n) where n is total number of goals

func (*InMemoryGoalCache) GetChallengeByChallengeID

func (c *InMemoryGoalCache) GetChallengeByChallengeID(challengeID string) *domain.Challenge

GetChallengeByChallengeID retrieves a challenge by its unique ID. Returns nil if the challenge does not exist. Time complexity: O(1)

func (*InMemoryGoalCache) GetGoalByID

func (c *InMemoryGoalCache) GetGoalByID(goalID string) *domain.Goal

GetGoalByID retrieves a goal by its unique ID. Returns nil if the goal does not exist. Time complexity: O(1)

func (*InMemoryGoalCache) GetGoalsByStatCode

func (c *InMemoryGoalCache) GetGoalsByStatCode(statCode string) []*domain.Goal

GetGoalsByStatCode retrieves all goals that track a specific stat code. Multiple goals can track the same stat (e.g., multiple challenges tracking "login_count"). Returns an empty slice if no goals track this stat. Time complexity: O(1)

func (*InMemoryGoalCache) GetGoalsWithDefaultAssigned added in v0.3.0

func (c *InMemoryGoalCache) GetGoalsWithDefaultAssigned() []*domain.Goal

GetGoalsWithDefaultAssigned retrieves all goals that have default_assigned = true. Used by initialization endpoint to determine which goals to assign to new players. Returns empty slice if no goals are marked as default assigned. Time complexity: O(n) where n is total number of goals

func (*InMemoryGoalCache) Reload

func (c *InMemoryGoalCache) Reload() error

Reload reloads the cache from the config file. In M1, this requires application restart (config is baked into Docker image). This method is provided for future use when hot-reload is supported.

Returns:

  • error: If config file cannot be read or validation fails

Jump to

Keyboard shortcuts

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