-
Notifications
You must be signed in to change notification settings - Fork 47
/
exchange_rates_cache.ex
53 lines (44 loc) · 1.14 KB
/
exchange_rates_cache.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
defmodule Money.ExchangeRates.Cache do
@moduledoc """
Defines a cache behaviour and default inplementation
of a cache for exchange rates
"""
@doc """
Initialize the cache when the exchange rates
retriever is started
"""
@callback init() :: any()
@doc """
Terminate the cache when the retriver process
stops normally
"""
@callback terminate() :: any()
@doc """
Retrieve the latest exchange rates from the
cache.
"""
@callback latest_rates() :: {:ok, map()} | {:error, {Exception.t(), String.t()}}
@doc """
Returns the exchange rates for a given
date.
"""
@callback historic_rates(Date.t()) :: {:ok, map()} | {:error, {Exception.t(), String.t()}}
@doc """
Store the latest exchange rates in the cache.
"""
@callback store_latest_rates(map(), DateTime.t()) :: :ok
@doc """
Store the historic exchange rates for a given
date in the cache.
"""
@callback store_historic_rates(map(), Date.t()) :: :ok
def latest_rates do
cache().latest_rates
end
def historic_rates(date) do
cache().historic_rates(date)
end
def cache do
Money.ExchangeRates.Retriever.config().cache_module
end
end