Class CachingPriceFeed
java.lang.Object
com.codename1.crypto.market.CachingPriceFeed
- All Implemented Interfaces:
PriceFeed
A PriceFeed that remembers each pair's answer for a while. A wallet screen that refreshes
every few seconds then asks the source once per pair per interval, which is what keeps it
inside a public API's rate limit. When the source fails and a remembered answer is no older
than the stale limit, that answer is returned rather than the failure.
The cache keeps at most 512 pairs and is not synchronized; on the backend give each thread its own or guard it.
-
Constructor Summary
ConstructorsConstructorDescriptionCachingPriceFeed(PriceFeed source, long freshMillis, long staleMillis) A cache answering from memory forfreshMillis, and on a source failure for up tostaleMillis. -
Method Summary
-
Constructor Details
-
CachingPriceFeed
A cache answering from memory forfreshMillis, and on a source failure for up tostaleMillis.
-
-
Method Details
-
getQuote
Description copied from interface:PriceFeedThe price of
baseinquote, by ticker (BTC,ETH,USD,EUR); case does not matter.Throws
IOException: when the source cannot be reached or does not know the pair
- Specified by:
getQuotein interfacePriceFeed- Throws:
IOException
-
clear
public void clear()Forgets every remembered answer. -
now
protected long now()The clock, in milliseconds; a test overrides it.
-