Pollex.NebulexCache (pollex v1.0.1)
View SourceThis module acts as a cache for data pulled from a configured file. It holds methods to referesh the cache and has functionality to the data up at any time.
Example usage:
Configure the cache
config :pollex, Pollex.Application, datasets: %{
cities: %{ refresh_interval_seconds: 6, cache: {NebulexCacheAdapter, [columns: [:name]]}, source: {EctoSourceAdapter, [table: Pollex.City, repo: Pollex.Repo]}, cache_runtime_opts: [ gc_interval: :timer.hours(12), max_size: 1_000_000, allocated_memory: 2_000_000_000, gc_cleanup_min_timeout: :timer.seconds(10), gc_cleanup_max_timeout: :timer.minutes(10) ] }}
You configure a dataset, and an interval. The application will start a Genserver process per dataset and run for you.
Get the data
iex> NebulexCache.lookup(:cities) iex> %{ "australia" => "australia", "austria" => "austria", "azerbaijan" => "azerbaijan", "germany" => "germany", "russia" => "russia", "united kingdom" => "united kingdom", "usa" => "usa" }
Summary
Functions
Returns a specification to start this module under a supervisor.
Represents the initial data provider It calls the handle cast Genserver callback to save the data in the state
Public api function which calls the Genserver callback to fetch the data
Represents the loop It sends the :poll message after a configured interval
This is the first function called when the Genserver process is initialised It configures a given name so we can have many Process of the same type
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec load(Ecto.Schema.t(), module(), [atom()]) :: {:ok, list()} | {:error, any()}
Represents the initial data provider It calls the handle cast Genserver callback to save the data in the state
Public api function which calls the Genserver callback to fetch the data
Example:
iex> NebulexCache.lookup(:cities)
iex>
%{
"australia" => "australia",
"austria" => "austria",
"azerbaijan" => "azerbaijan",
"germany" => "germany",
"russia" => "russia",
"united kingdom" => "united kingdom",
"usa" => "usa"
}
Represents the loop It sends the :poll message after a configured interval
This is the first function called when the Genserver process is initialised It configures a given name so we can have many Process of the same type