Exemplo n.º 1
0
  @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;
  }
Exemplo n.º 2
0
 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");
       }
     }
   }
 }
Exemplo n.º 3
0
 @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);
     }
   }
 }
Exemplo n.º 4
0
 @Override
 public void clear() {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Clearing the cache");
       cache.clear();
     }
   }
 }
Exemplo n.º 5
0
 @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);
     }
   }
 }
Exemplo n.º 6
0
 @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);
     }
   }
 }
Exemplo n.º 7
0
 @Override
 public void init() {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Initializing cache");
       cache.init();
     }
   }
 }