@Override @Nullable public Entry get(@Nonnull Key key) { if (cache != null) { synchronized (this) { final Entry entry = cache.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); cache.remove(key); return null; } Billing.debug(TAG, "Key=" + key + " is in the cache"); return entry; } } return null; }
public void putIfNotExist(@Nonnull Key key, @Nonnull Entry entry) { if (cache != null) { synchronized (this) { if (cache.get(key) == null) { Billing.debug(TAG, "Adding entry with key=" + key + " to the cache"); cache.put(key, entry); } else { Billing.debug(TAG, "Entry with key=" + key + " is already in the cache, won't add"); } } } }
@Override public void put(@Nonnull Key key, @Nonnull Entry entry) { if (cache != null) { synchronized (this) { Billing.debug(TAG, "Adding entry with key=" + key + " to the cache"); cache.put(key, entry); } } }
@Override public void clear() { if (cache != null) { synchronized (this) { Billing.debug(TAG, "Clearing the cache"); cache.clear(); } } }
@Override public void removeAll(int type) { if (cache != null) { synchronized (this) { Billing.debug(TAG, "Removing all entries with type=" + type + " from the cache"); cache.removeAll(type); } } }
@Override public void remove(@Nonnull Key key) { if (cache != null) { synchronized (this) { Billing.debug(TAG, "Removing entry with key=" + key + " from the cache"); cache.remove(key); } } }
@Override public void init() { if (cache != null) { synchronized (this) { Billing.debug(TAG, "Initializing cache"); cache.init(); } } }