Pollex.CSVGenServerCache (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: {GenServerCacheAdapter, [columns: [:name]]}, source: {EctoSourceAdapter, [table: Pollex.City, repo: Pollex.Repo]} }}
You configure a dataset, and an interval. The application will start a Genserver process per dataset and run for you.
Get the data
iex> EctoGenServerCache.lookup(:cities) iex> [ %{name: "germany"}, %{name: "usa"}, %{name: "australia"}, %{name: "united kingdom"}, %{name: "austria"} ]
Summary
Functions
Returns a specification to start this module under a supervisor.
Callback implementation for Pollex.SrcAdapter.CSVFileSourceAdapter.load/1.
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.
Callback implementation for Pollex.SrcAdapter.CSVFileSourceAdapter.load/1.
Public api function which calls the Genserver callback to fetch the data
Example:
iex> CSVGenServerCache.lookup(:countries)
iex>
[
%{"code" => "de", "name" => "Germany"},
%{"code" => "us", "name" => "United States of America"},
%{"code" => "au", "name" => "Australia"},
%{"code" => "uk", "name" => "United kingdom"},
%{"code" => "at", "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