New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[android] migrate OkHttp cache to application cache directory #11600
Conversation
android/expoview/src/main/java/host/exp/exponent/network/ExponentNetwork.java
Outdated
Show resolved
Hide resolved
android/expoview/src/main/java/host/exp/exponent/network/ExponentNetwork.java
Outdated
Show resolved
Hide resolved
android/expoview/src/main/java/host/exp/exponent/ReactNativeStaticHelpers.java
Show resolved
Hide resolved
26c7232
to
1de7a58
Compare
@@ -56,6 +56,7 @@ | |||
public static final String SAFE_MANIFEST_KEY = "safe_manifest"; | |||
public static final String EXPO_AUTH_SESSION = "expo_auth_session"; | |||
public static final String EXPO_AUTH_SESSION_SECRET_KEY = "sessionSecret"; | |||
public static final String HAS_CLEARED_LEGACY_OKHTTP_CACHE_KEY = "has_cleared_legacy_okhttp_cache"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit hesitant to put a key called has_cleared_legacy_okhttp_cache
on devices with newly installed apps that aren't affected at all by this cache transition. A more forward-looking approach would be to have a key like okhttp_cache_version
with the value 1
(no key = we need to try to clear the cache). Then if we were to make cache changes in the future, we could bump this key from 1 to 2.
# Why Follow-up to #11599. Since OTA update assets are stored in a separate location, it's better to keep the OkHttp cache in the application cache directory, rather than the files directory -- this allows the OS to clean up files if it needs to, and reduces the chance that developers' application code will unexpectedly interfere with the OkHttp cache. # How - Moved OkHttp cache to `Context.getCacheDir`, and renamed it to match the name of bare RN OkHttp caches. - Added some deletion logic for the old cache in `Context.getFilesDir`. After deleting we set a key in SharedPreferences so we don't try to delete again. - Also increased the maximum cache size to 50Mb -- this is [recommended in the OkHttp docs](https://square.github.io/okhttp/caching/). I checked [`StorageManager.getCacheQuotaBytes`](https://developer.android.com/reference/android/os/storage/StorageManager#getCacheQuotaBytes(java.util.UUID)) for the cache directory of a fresh installation of the Expo Go client on my Pixel 2, and got 64Mb. Since the cache directory also includes a few other caches (image, picasso, home experience data) 50Mb seems like a reasonable maximum size for the OkHttp cache. - Finally, removed some extraneous logic around the OkHttpClient builder that was specifically for ExpoKit apps. # Test Plan Ran the same tests from #11599 again.
Why
Follow-up to #11599. Since OTA update assets are stored in a separate location, it's better to keep the OkHttp cache in the application cache directory, rather than the files directory -- this allows the OS to clean up files if it needs to, and reduces the chance that developers' application code will unexpectedly interfere with the OkHttp cache.
How
Context.getCacheDir
, and renamed it to match the name of bare RN OkHttp caches.Context.getFilesDir
. After deleting we set a key in SharedPreferences so we don't try to delete again.StorageManager.getCacheQuotaBytes
for the cache directory of a fresh installation of the Expo Go client on my Pixel 2, and got 64Mb. Since the cache directory also includes a few other caches (image, picasso, home experience data) 50Mb seems like a reasonable maximum size for the OkHttp cache.Test Plan
Ran the same tests from #11599 again.