Skip to content

Instantly share code, notes, and snippets.

@mtilbrook-dev
Created May 30, 2018 21:28
Show Gist options
  • Save mtilbrook-dev/ef9a6393964adf76c154cac99e6109f3 to your computer and use it in GitHub Desktop.
Save mtilbrook-dev/ef9a6393964adf76c154cac99e6109f3 to your computer and use it in GitHub Desktop.
@Module
object AppModule {
private const val HTTP_RESPONSE_CACHE = (10 * 1024 * 1024).toLong()
@AppScope @Provides @JvmStatic
fun httpClient(cache: Cache): OkHttpClient {
if (Looper.getMainLooper() == Looper.myLooper())
throw IllegalStateException("Initializing OkHttpClient on main thread.")
return OkHttpClient.Builder()
.cache(cache)
.build()
}
@AppScope @Provides @JvmStatic
fun cache(@AppContext context: Context): Cache {
if (Looper.getMainLooper() == Looper.myLooper())
throw IllegalStateException("Initializing cache on main thread.")
return Cache(context.cacheDir, HTTP_RESPONSE_CACHE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment