@Override public void onPurchasesChanged() { mCache.removeAll(RequestType.GET_PURCHASES.getCacheKeyType()); } };
@Nonnull Cache.Key getCacheKey(@Nonnull String key) { final int keyType = getCacheKeyType(); return new Cache.Key(keyType, key); }
@Override public void onSuccess(@Nonnull Purchase result) { mCache.removeAll(RequestType.GET_PURCHASES.getCacheKeyType()); super.onSuccess(result); } };
@Override public void onError(int response, @Nonnull Exception e) { final RequestType type = mRequest.getType(); // sometimes it is possible that cached data is not synchronized with data on Google Play => we can // clear caches if such situation occurs switch (type) { case PURCHASE: case CHANGE_PURCHASE: if (response == ITEM_ALREADY_OWNED) { mCache.removeAll(RequestType.GET_PURCHASES.getCacheKeyType()); } break; case CONSUME_PURCHASE: if (response == ITEM_NOT_OWNED) { mCache.removeAll(RequestType.GET_PURCHASES.getCacheKeyType()); } break; } super.onError(response, e); } }
@Override public void onSuccess(@Nonnull R result) { final String key = mRequest.getCacheKey(); final RequestType type = mRequest.getType(); if (key != null) { final long now = currentTimeMillis(); final Cache.Entry entry = new Cache.Entry(result, now + type.expiresIn); mCache.putIfNotExist(type.getCacheKey(key), entry); } switch (type) { case PURCHASE: case CHANGE_PURCHASE: case CONSUME_PURCHASE: // these requests might affect the state of purchases => we need to invalidate caches. // see Billing#onPurchaseFinished() also mCache.removeAll(RequestType.GET_PURCHASES.getCacheKeyType()); break; } super.onSuccess(result); }