Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Last active October 28, 2020 10:18
Show Gist options
  • Save Ikhiloya/526f3e4eb168acdb24d9e3a92aa4670b to your computer and use it in GitHub Desktop.
Save Ikhiloya/526f3e4eb168acdb24d9e3a92aa4670b to your computer and use it in GitHub Desktop.
Network interceptor for caching requests when there is network connection
class NetworkInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
Timber.d("network interceptor: called.")
val response = chain.proceed(chain.request())
val cacheControl = CacheControl.Builder()
.maxAge(5, TimeUnit.SECONDS)
.build()
return response.newBuilder()
.removeHeader(HEADER_PRAGMA)
.removeHeader(HEADER_CACHE_CONTROL)
.header(HEADER_CACHE_CONTROL, cacheControl.toString())
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment