I have seen many answers suggest that one should Invalid Caches/Restart in order to improve the performance of Android Studio, whether it's memory or CPU. It also can be used to set up correct themes. I was wondering what it actually does though, since it seems to be the solution to so many problems.
Invalidate Cache clears project structure related information (only) cached by Android studio.
Invalidation of a cache or cache line means to clear it of data. This is done by clearing the valid bit of one or more cache lines. The cache must always be invalidated after reset as its contents will be undefined. If the cache contains dirty data, it is generally incorrect to invalidate it.
If the user needs to delete any library cache of a project, they have to traverse through the . gradle/cache/modules-2/files-2.1 and . gradle/cache/modules-2/metadata-x.
Android Studio makes a lot of files as caches and does not delete them. This can cause trouble when there is a need to make new files, so clearing caches will clear the old cache and make Android Studio faster.
Invalidate Cache clears project structure related information (only) cached by Android studio. Please note that this cache is different from "Build Cache" and "Gradle cache" briefly explained below.
Build Cache - stores certain outputs that the Android plugin for Gradle generates when building your project e.g. unpackaged AARs and pre-dexed remote dependencies. Build cache is enabled by default in recent plugins (2.3.0+).
Build Cache path: C:\Users\[User_Name]\.android\build-cache\gradleVersion
Here version value is driven by value defined in build.gradle file in your project. e.g. classpath "com.android.tools.build:gradle:$gradleVersion" Invalidate Cache has no impact on Build Cache. It can be cleared using "gradlew cleanBuildCache" command instead.
Gradle Cache - maintains Download Dependencies.
Gradle Cache path: C:\Users[user_name]\.gradle\caches\modules-2\files-2.1 [Windows] ~/.gradle/caches/modules-2/files-2.1 [Mac]
Also, as mentioned by @anurag, Clean Project has no relation to Build Cache.
More @ https://developer.android.com/studio/build/build-cache
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With