abstract class OnlineRepository<CACHE, GET_CACHE_REQUIREMENTS : GetCacheRequirements, FETCH_RESPONSE>
Teller repository that manages a cache that is obtained from a network fetch request.
Using OnlineRepository is quite simple:
OnlineRepository is thread safe. Actions called upon for OnlineRepository can be performed on any thread.
class FetchResponse<FETCH_RESPONSE>
When a OnlineRepository.fetchFreshCache task is performed, Teller needs to know if the fetch request is considered to be a success or a failure. |
|
interface GetCacheRequirements
Used by Teller to determine what chunk of cache to fetch and query. |
|
class RefreshResult
Result object of a call to OnlineRepository.refresh. Understand if a refresh call was successful, not successful, or skipped for some reason. |
|
object Testing
Used for testing purposes to initialize the state of a OnlineRepository subclass instance. |
OnlineRepository() |
abstract var maxAgeOfCache: Age
Used to set how old cache can be on the device before it is considered too old and new cache should be fetched. |
|
var requirements: GET_CACHE_REQUIREMENTS?
Requirements needed to be able to load cache from the device and to fetch new cache from the network. |
fun dispose(): Unit
Dispose of the OnlineRepository to shut down observing of the cache and stops refresh tasks if they have begun. |
|
abstract fun fetchFreshCache(requirements: GET_CACHE_REQUIREMENTS): Single<FetchResponse<FETCH_RESPONSE>>
Repository does what it needs in order to fetch fresh cache. Probably call network API. |
|
abstract fun isCacheEmpty(cache: CACHE, requirements: GET_CACHE_REQUIREMENTS): Boolean
Used to determine if cache is empty or not. |
|
fun observe(): Observable<OnlineCacheState<CACHE>>
How to begin observing the state of the cache for this OnlineRepository. |
|
abstract fun observeCache(requirements: GET_CACHE_REQUIREMENTS): Observable<CACHE>
Get existing cache saved on the device if it exists. If no cache exists, return an empty response set in the Observable and return true in isCacheEmpty. Do not return nil or an Observable with nil as a value as this will cause an exception. |
|
fun refresh(force: Boolean): Single<RefreshResult>
Manually perform a refresh of the cache. |
|
abstract fun saveCache(cache: FETCH_RESPONSE, requirements: GET_CACHE_REQUIREMENTS): Unit
Save the new cache cache to whatever storage method OnlineRepository chooses. |