From e4cbe146d446262dd07f43f468437de381c6515a Mon Sep 17 00:00:00 2001 From: Shrutika Pradeep Girme Date: Fri, 14 Apr 2023 17:38:42 +0530 Subject: [PATCH] added a method to set debug mode --- .../com/myntra/objectcache/ObjectCache.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/objectcache/src/main/java/com/myntra/objectcache/ObjectCache.java b/objectcache/src/main/java/com/myntra/objectcache/ObjectCache.java index 4115158..094c049 100644 --- a/objectcache/src/main/java/com/myntra/objectcache/ObjectCache.java +++ b/objectcache/src/main/java/com/myntra/objectcache/ObjectCache.java @@ -12,8 +12,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.myntra.objectcache.BuildConfig; - /** * @author mario */ @@ -25,6 +23,8 @@ public class ObjectCache { static final String STRING_KEY_PATTERN = "[a-z0-9_-]{1,120}"; public static final Pattern LEGAL_KEY_PATTERN = Pattern.compile(STRING_KEY_PATTERN); + private static boolean debugMode = false; + public static ObjectCache defaultCache(File cacheDir, int appVersion) { return cacheInstance(cacheDir, DEFAULT_CACHE_DIR, appVersion); } @@ -35,7 +35,7 @@ public static ObjectCache cacheInstance(File cacheDir, String folder, int appVer try { objectCache.cache = DiskLruCache.open(file, appVersion, 1, SIZE); } catch (IOException e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } return objectCache; @@ -47,12 +47,16 @@ public static ObjectCache cacheInstance(File cacheDir, String folder, int appVer try { objectCache.cache = DiskLruCache.open(file, appVersion, 1, size); } catch (IOException e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } return objectCache; } + public static void setDebugBuild(boolean mode) { + debugMode = mode; + } + public void write(String key, Object object, long expiry) { key = sanitizeKey(key); try { @@ -63,7 +67,7 @@ public void write(String key, Object object, long expiry) { cache.flush(); editor.commit(); } catch (IOException e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } } @@ -85,7 +89,7 @@ public T fetch(String key, Class classOfT) { } } } catch (Exception e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } return null; @@ -101,7 +105,7 @@ public T fetchEvenIfExpired(String key, Class classOfT) { return gson.fromJson(entryJson.getAsJsonObject(Entry.VALUE), classOfT); } } catch (IOException e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } return null; @@ -117,7 +121,7 @@ public Boolean hasExpired(String key) { return entry.hasExpired(); } } catch (IOException e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } return null; @@ -128,7 +132,7 @@ public boolean remove(String key) { try { return cache.remove(key); } catch (IOException e) { - if(BuildConfig.DEBUG) + if(debugMode) e.printStackTrace(); } return false;