Forex.Cache behaviour (Forex v0.2.2)
View SourceSince 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.
You can override the cache module by setting the :cache_module configuration
option in the Forex.Fetcher module options.
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.