From 78849fd388041d8727325aa654de31dcb8088786 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 8 Jun 2011 11:51:55 -0700 Subject: [PATCH] Lock cache puts while running tests Change-Id: I04c88ee70f9d72252fd1c5114d560a28fcee1b56 --- src/com/android/email/provider/ContentCache.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/com/android/email/provider/ContentCache.java b/src/com/android/email/provider/ContentCache.java index 8f5978371..ab3f37f28 100644 --- a/src/com/android/email/provider/ContentCache.java +++ b/src/com/android/email/provider/ContentCache.java @@ -105,6 +105,8 @@ public final class ContentCache { private final String mLogTag; // Cache statistics private final Statistics mStats; + /** If {@code true}, lock the cache for all writes */ + private static boolean sLockCache; /** * A synchronized reference counter for arbitrary objects @@ -465,7 +467,7 @@ public final class ContentCache { mStats.mStaleCount++; return c; } - if (c != null && projection == mBaseProjection) { + if (c != null && projection == mBaseProjection && !sLockCache) { if (Email.DEBUG && DEBUG_CACHE) { Log.d(mLogTag, "============ Caching cursor for: " + id); } @@ -611,7 +613,7 @@ public final class ContentCache { if (Email.DEBUG && DEBUG_CACHE) { Log.d(mLogTag, "=========== Unlocking cache for: " + id); } - if (values != null) { + if (values != null && !sLockCache) { MatrixCursor cursor = getMatrixCursor(id, mBaseProjection, values); if (cursor != null) { if (Email.DEBUG && DEBUG_CACHE) { @@ -727,6 +729,14 @@ public final class ContentCache { } } + /** Sets the cache lock. If the lock is {@code true}, also invalidates all cached items. */ + public static void setLockCacheForTest(boolean lock) { + sLockCache = lock; + if (sLockCache) { + invalidateAllCachesForTest(); + } + } + static class Statistics { private final ContentCache mCache; private final String mName;