Pollex.CSVGenServerCache (pollex v1.0.1)

View Source

This 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:

  1. 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.

  1. 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.

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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

load(file_name)

@spec load(String.t()) :: {:ok, list()} | {:error, any()}

Callback implementation for Pollex.SrcAdapter.CSVFileSourceAdapter.load/1.

lookup(name)

@spec lookup(atom()) :: [map()]
@spec lookup(atom()) :: [map()]

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"}
]

schedule_refresh(interval)

@spec schedule_refresh(integer()) :: any()

Represents the loop It sends the :poll message after a configured interval

start_link(opts)

@spec start_link(keyword()) :: :ignore | {:error, any()} | {:ok, pid()}

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