|
1 | 1 | defmodule Posthog.Application do
|
2 |
| - @moduledoc false |
| 2 | + @moduledoc """ |
| 3 | + The main application module for PostHog Elixir client. |
| 4 | +
|
| 5 | + This module handles the application lifecycle and supervises the necessary processes |
| 6 | + for the PostHog client to function properly. It primarily manages the Cachex instance |
| 7 | + used for feature flag event deduplication. |
| 8 | +
|
| 9 | + ## Features |
| 10 | +
|
| 11 | + * Validates configuration before starting |
| 12 | + * Manages a Cachex instance for feature flag event deduplication |
| 13 | + * Implements LRU (Least Recently Used) caching strategy |
| 14 | + * Automatically prunes cache entries to maintain size limits |
| 15 | +
|
| 16 | + ## Cache Configuration |
| 17 | +
|
| 18 | + The Cachex instance is configured with: |
| 19 | + * Maximum of 50,000 entries (matching posthog-python's limit) |
| 20 | + * LRU (Least Recently Used) eviction policy |
| 21 | + * Automatic pruning every 10 seconds |
| 22 | + * Access tracking for LRU implementation |
| 23 | +
|
| 24 | + ## Usage |
| 25 | +
|
| 26 | + The application is automatically started by the Elixir runtime when included |
| 27 | + in your application's supervision tree. You don't need to start it manually. |
| 28 | +
|
| 29 | + To access the cache name in your code: |
| 30 | +
|
| 31 | + Posthog.Application.cache_name() |
| 32 | + # Returns: :posthog_feature_flag_cache |
| 33 | + """ |
3 | 34 |
|
4 | 35 | use Application
|
5 | 36 | import Cachex.Spec
|
6 | 37 |
|
7 | 38 | @cache_name :posthog_feature_flag_cache
|
| 39 | + |
| 40 | + @doc """ |
| 41 | + Returns the name of the Cachex instance used for feature flag event deduplication. |
| 42 | +
|
| 43 | + ## Returns |
| 44 | +
|
| 45 | + * `atom()` - The cache name, always `:posthog_feature_flag_cache` at the moment |
| 46 | +
|
| 47 | + ## Examples |
| 48 | +
|
| 49 | + iex> Posthog.Application.cache_name() |
| 50 | + :posthog_feature_flag_cache |
| 51 | + """ |
8 | 52 | def cache_name, do: @cache_name
|
9 | 53 |
|
| 54 | + @doc """ |
| 55 | + Starts the PostHog application. |
| 56 | +
|
| 57 | + This callback is called by the Elixir runtime when the application starts. |
| 58 | + It performs the following tasks: |
| 59 | + 1. Validates the PostHog configuration |
| 60 | + 2. Sets up the Cachex instance for feature flag event deduplication |
| 61 | + 3. Starts the supervision tree |
| 62 | +
|
| 63 | + ## Parameters |
| 64 | +
|
| 65 | + * `_type` - The type of start (ignored) |
| 66 | + * `args` - Keyword list of arguments, can include: |
| 67 | +
|
| 68 | + ## Returns |
| 69 | +
|
| 70 | + * `{:ok, pid()}` on successful start |
| 71 | + * `{:error, term()}` on failure |
| 72 | +
|
| 73 | + ## Examples |
| 74 | +
|
| 75 | + # Start with default configuration |
| 76 | + Posthog.Application.start(:normal, []) |
| 77 | + """ |
10 | 78 | def start(_type, args) do
|
11 | 79 | # Validate configuration before starting
|
12 | 80 | Posthog.Config.validate_config!()
|
|
0 commit comments