From b15f9bf26e68b794f8abc4286ab5c51d312bb3d5 Mon Sep 17 00:00:00 2001 From: Gabriel Peal Date: Sun, 29 Sep 2024 10:15:15 -0700 Subject: [PATCH] Add an option to not clear the network cache (#2559) Fixes #2498 --- .../lottie/LottieCompositionFactory.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieCompositionFactory.java b/lottie/src/main/java/com/airbnb/lottie/LottieCompositionFactory.java index be5ca0501c..e309d095ae 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieCompositionFactory.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieCompositionFactory.java @@ -86,12 +86,27 @@ public static void setMaxCacheSize(int size) { LottieCompositionCache.getInstance().resize(size); } + /** + * Like {@link #clearCache(Context, boolean)} but defaults to clearing the network cache. + * + * @see #clearCache(Context, boolean) + */ public static void clearCache(Context context) { + clearCache(context, true); + } + + /** + * Clears any pending animations, animations that are parsed and in-memory, and + * optionally, any animations loaded from the network that are cached to disk. + */ + public static void clearCache(Context context, boolean includeNetwork) { taskCache.clear(); LottieCompositionCache.getInstance().clear(); - final NetworkCache networkCache = L.networkCache(context); - if (networkCache != null) { - networkCache.clear(); + if (includeNetwork) { + final NetworkCache networkCache = L.networkCache(context); + if (networkCache != null) { + networkCache.clear(); + } } }