rama::proxy

Function proxy_db_updater

pub fn proxy_db_updater<T>() -> (LiveUpdateProxyDB<T>, LiveUpdateProxyDBSetter<T>)
where T: ProxyDB, <T as ProxyDB>::Error: Into<Box<dyn Error + Sync + Send>>,
Expand description

Create a new ProxyDB updater which allows you to have a (typically in-memory) ProxyDB which you can update live.

This construct returns a pair of:

Note that the inner T is not yet created when this construct returns this pair. Until you actually called LiveUpdateProxyDBSetter::set with the inner T ProxyDB, any ProxyDB trait method call to LiveUpdateProxyDB will fail.

It is therefore recommended that you immediately set the inner T ProxyDB upon receiving the reader/writer pair, prior to starting to actually use the ProxyDB in your rama service stack.

This goal of this updater is to be fast for reading (getting proxies), and slow for the infrequent updates (setting the proxy db). As such it is recommended to not update the ProxyDB to frequent. An example use case for this updater could be to update your in-memory proxy database every 15 minutes, by populating it from a shared external database (e.g. MySQL). Failures to create a new T` ProxyDB should be handled by the Writer, and can be as simple as just logging it and move on without an update.