@Override @Nullable public Entry get(@Nonnull Key key) { try { return mCache.get(key); } catch (Exception e) { Billing.error(e); return null; } }
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"); } } }
@Override @Nullable public Entry get(@Nonnull Key key) { if (mCache == null) { return null; } synchronized (this) { final Entry entry = mCache.get(key); if (entry == null) { Billing.debug(TAG, "Key=" + key + " is not in the cache"); return null; } final long now = currentTimeMillis(); if (now >= entry.expiresAt) { Billing.debug(TAG, "Key=" + key + " is in the cache but was expired at " + entry.expiresAt + ", now is " + now); mCache.remove(key); return null; } Billing.debug(TAG, "Key=" + key + " is in the cache"); return entry; } }