public final class InMemoryIconCache extends AbstractIconCache implements IconCache
IconCache stores the icons in the memory by using a static field.
The implementation will reused the stored icons. Whenever the JVM is killed the cache is onResetView. This means the class will reuse the stored icons as long as the app is running. On a restart the icons will be refreshed.
For most use cases this is a desired behavior because at some point the data has to be removed resp. refreshed. We use the app restart to onResetView the cache and reload the icons.
AbstractIconCache.CacheKeyDEFAULT_ICON_LOADING_TIMEOUT| Constructor and Description |
|---|
InMemoryIconCache(IconRequestManager iconRequestManager,
long timeout)
Constructs an instance based on a
IconRequestManager. |
| Modifier and Type | Method and Description |
|---|---|
protected PaymentMethodIcon |
lookupInLocalCache(AbstractIconCache.CacheKey cacheKey)
This method is invoked to try to load the icon from the local cache.
|
protected void |
lookupInRemoteServer(AbstractIconCache.CacheKey cacheKey,
RequestCallback<PaymentMethodIcon> callback)
This method has to query the remote host to fetch the icon.
|
protected void |
putInLocalCache(AbstractIconCache.CacheKey cacheKey,
PaymentMethodIcon icon)
This method is invoked to persist an entry into the local cache.
|
fetchIcons, loadIconclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfetchIcons, loadIconpublic InMemoryIconCache(IconRequestManager iconRequestManager, long timeout)
IconRequestManager.iconRequestManager - the request manager to use.timeout - the timeout which cannot be exceeded when multiple icons are
loaded. The time is in milliseconds.protected PaymentMethodIcon lookupInLocalCache(AbstractIconCache.CacheKey cacheKey)
AbstractIconCachenull when the entry does not exists.
This method has to be implemented in a thread-safe manner.
lookupInLocalCache in class AbstractIconCachecacheKey - the payment method configuration for which the icon should
be looked up.null when it does not exists.protected void lookupInRemoteServer(AbstractIconCache.CacheKey cacheKey, RequestCallback<PaymentMethodIcon> callback)
AbstractIconCacheThis method has to be implemented in a thread-safe manner.
lookupInRemoteServer in class AbstractIconCachecacheKey - the payment method configuration for which the icon should
be fetched for.callback - the callback which has to be invoked once the loading has
been completed.protected void putInLocalCache(AbstractIconCache.CacheKey cacheKey, PaymentMethodIcon icon)
AbstractIconCacheThis method has to be implemented in a thread-safe manner.
putInLocalCache in class AbstractIconCachecacheKey - the payment method configuration for which the icon should
be stored for.icon - the icon which should be stored.