Last active
March 28, 2025 10:53
-
-
Save hardikm9850/64acc76d9cc15ae349863737e4597ba4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Creating cache folder where our response will be cached | |
| val cacheFolder = Cache(File(applicationContext.cacheDir, "http-cache"), 10L * 1024L * 1024L) // 10 MB Cache | |
| // Creating the okhttp builder passing the CacheInterceptor that adds "Cache-Control" in server's header | |
| val okHttpClient = OkHttpClient().newBuilder() | |
| .cache(cacheFolder) | |
| .addNetworkInterceptor(CacheInterceptor()) // Only intercepts network responses (i.e. responses fetched from the server, not the cache) | |
| .build() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment