Since the ECB reference rates are usually updated at around 16:00 CET every working day we should cache the response.
This module defines a simple caching layer behaviour to cache the
responses from the Forex.Feed module.
The default implementation uses ETS as the cache storage (Forex.Cache.ETS adapter).
You can override the cache module by setting the :cache_module configuration option,
but it must implement the Forex.Cache behaviour. For example, to use a custom cache
module, you can set the configuration like this:
config :forex, cache_module: MyApp.ForexCacheThere is also a Forex.Cache.DETS adapter that uses DETS for persistent storage,
which can be useful for testing or if you want to persist the cache across
application restarts. Take into consideration that when using DETS, the
path to the cache file must be a writable directory and the file will
be created if it does not exist.
Summary
Callbacks
Delete an entry from the cache with the given key.
Get the cache entry with the given key.
Returns nil if the entry does not exist.
Inits the cache.
Check if the cache is initialized.
Get a list of all keys in the cache and the respective updated at timestamps.
Get the latest updated at timestamp for the given key.
Returns nil if the entry does not exist.
Put a new entry into the cache with the given key and value.
Reset the cache table.
Resolve the cache entry with the given key using the given resolver.
If the entry does not exist, the resolver function, an mfa tuple, is called and the
result is stored in the cache.
Terminate the cache process.
Callbacks
Delete an entry from the cache with the given key.
Get the cache entry with the given key.
Returns nil if the entry does not exist.
@callback init() :: any()
Inits the cache.
@callback initialized?() :: boolean()
Check if the cache is initialized.
@callback last_updated() :: [{any(), DateTime.t()}] | nil
Get a list of all keys in the cache and the respective updated at timestamps.
@callback last_updated(key :: any()) :: DateTime.t() | nil
Get the latest updated at timestamp for the given key.
Returns nil if the entry does not exist.
@callback put(key :: any(), value :: term(), DateTime.t()) :: term()
Put a new entry into the cache with the given key and value.
@callback reset() :: any()
Reset the cache table.
Resolve the cache entry with the given key using the given resolver.
If the entry does not exist, the resolver function, an mfa tuple, is called and the
result is stored in the cache.
Example:
Forex.Cache.resolve(:latest_rates, {Forex.Feed, :fetch_latest_rates, []})
@callback terminate() :: any()
Terminate the cache process.