View Source Plausible.Site.Cache (Plausible v0.0.1)

The cache allows lookups by both domain and domain_changed_from fields - this is to allow traffic from sites whose domains changed within a certain grace period (see: Plausible.Site.Transfer).

To differentiate cached Site structs from those retrieved directly from the database, a virtual schema field from_cache?: true is set. This indicates the Plausible.Site struct is incomplete in comparison to its database counterpart -- to spare bandwidth and query execution time, only selected database columns are retrieved and cached.

The @cached_schema_fields attribute defines the list of DB columns queried on each cache refresh.

Also see tests for more comprehensive examples.

Summary

Functions

@spec child_spec(Keyword.t()) :: Supervisor.child_spec()
@spec get(String.t(), Keyword.t()) :: any() | nil
Link to this function

get_site_id(domain, opts \\ [])

View Source
@spec get_site_id(String.t(), Keyword.t()) :: pos_integer() | nil
Link to this function

hit_rate(cache_name \\ name())

View Source
Link to this function

merge_items(new_items, opts \\ [])

View Source
@spec merge_items(new_items :: [any()], opts :: Keyword.t()) :: :ok
Link to this function

ready?(cache_name \\ name())

View Source
@spec ready?(atom()) :: boolean()

Ensures the cache has non-zero size unless no items exist. Useful for orchestrating app startup to prevent the service going up asynchronously with an empty cache.

@spec refresh_all(Keyword.t()) :: :ok
Link to this function

refresh_updated_recently(opts \\ [])

View Source
@spec refresh_updated_recently(Keyword.t()) :: :ok
Link to this function

size(cache_name \\ name())

View Source
Link to this function

telemetry_event_refresh(cache_name \\ name(), mode)

View Source
@spec telemetry_event_refresh(atom(), atom()) :: [atom()]
@spec touch_site!(Plausible.Site.t(), DateTime.t()) :: Plausible.Site.t()