@Override public void put(@Nonnull Key key, @Nonnull Entry entry) { try { mCache.put(key, entry); } catch (Exception e) { Billing.error(e); } }
@Override public void put(@Nonnull Key key, @Nonnull Entry entry) { if (mCache == null) { return; } synchronized (this) { Billing.debug(TAG, "Adding entry with key=" + key + " to the cache"); mCache.put(key, entry); } }
public void putIfNotExist(@Nonnull Key key, @Nonnull Entry entry) { if (mCache == null) { return; } synchronized (this) { if (mCache.get(key) == null) { Billing.debug(TAG, "Adding entry with key=" + key + " to the cache"); mCache.put(key, entry); } else { Billing.debug(TAG, "Entry with key=" + key + " is already in the cache, won't add"); } } }
@Test public void testShouldPutAllEntries() throws Exception { final Cache mockCache = mock(Cache.class); final ConcurrentCache cache = new ConcurrentCache(mockCache); final Cache.Entry entry = newEntry(); cache.put(newKey(), entry); cache.put(newKey(), entry); cache.put(newKey(), entry); verify(mockCache, times(3)).put(any(Cache.Key.class), eq(entry)); }