teller / com.levibostian.teller.repository / LocalRepository

LocalRepository

abstract class LocalRepository<CACHE : Any, GET_CACHE_REQUIREMENTS : GetCacheRequirements>

Teller repository that manages cache that is obtained and stored on the local device.

Using LocalRepository is quite simple:

  1. Subclass LocalRepository for each of your cache data types
  2. Call observe to begin observing the current state of the cached data.
  3. Set requirements with an object used to querying cached data. Set requirements object as many times as you wish and have observe receive all of the changes.

LocalRepository is thread safe. Actions called upon for LocalRepository can be performed on any thread.

Types

GetCacheRequirements

interface GetCacheRequirements

Constructors

<init>

LocalRepository()

Properties

requirements

var requirements: GET_CACHE_REQUIREMENTS?

Functions

dispose

fun dispose(): Unit

Dispose of the LocalRepository to shut down observing of cached data.

isCacheEmpty

abstract fun isCacheEmpty(cache: CACHE, requirements: GET_CACHE_REQUIREMENTS): Boolean

Determines if cache is empty or not. This is used internally by Teller to determine if the cache from observeCache is empty or not to then pass to LocalDataState.deliverState with the state of the cache.

newCache

fun newCache(cache: CACHE, requirements: GET_CACHE_REQUIREMENTS): Unit

Save new cache data.

observe

fun observe(): Observable<LocalDataState<CACHE>>

Get an observable that gets the current state of data and all future states.

observeCache

abstract fun observeCache(requirements: GET_CACHE_REQUIREMENTS): Observable<CACHE>

This function should be setup to trigger anytime there is a data change. So if you were to call saveCache, anyone observing the Observable returned here will get notified of a new update.

saveCache

abstract fun saveCache(cache: CACHE, requirements: GET_CACHE_REQUIREMENTS): Unit

Save new cache data to whatever storage method Repository chooses.