Pollex.AlphabeticNebulexCache (pollex v1.0.1)
View SourceThis module acts as a cache for data pulled from a configured database. It holds methods to referesh the cache and has functionality to the data up at any time. This cache strategy implements the Nebulex cache to support more advanced cache runtime options. Basically this cache creates a dynamic module which implements the Nebulex cache module. This module then uses the optimised sub module to store data.
Example usage:
- Configure the cache
config :pollex, Pollex.Application,
datasets: %{
cities: %{
refresh_interval_seconds: 6,
query_column: :name,
cache: {NebulexCacheAdapter, [columns: [:name, :country]]},
source: {AlphabeticAdapter, [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, an interval, a table, repo and the columns you want to fetch. The application will start a Genserver process per letter in the alphabet holding the data starting with that letter and run for you.
Get the data
iex> AlphabeticNebulexCache.lookup(:a) iex> [ %{name: "australia"}, %{name: "austria"} ]
Summary
Functions
Returns a specification to start this module under a supervisor.
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.
Public api function which calls the Genserver callback to fetch the data
Example:
iex> AlphabeticNebulexCache.lookup(:a)
iex>
[
%{name: "australia"},
%{name: "austria"}
]
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