@Test public void testClearAll() { LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION); NormalizedCache primaryCacheStore = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION) .chain(secondaryCacheFactory).createChain(basicFieldAdapter); Record record = Record.builder("key").build(); primaryCacheStore.merge(record, CacheHeaders.NONE); primaryCacheStore.clearAll(); assertThat(primaryCacheStore.loadRecord("key", CacheHeaders.NONE)).isNull(); }
@Override public void didResolveObject(ResponseField field, Optional<R> objectSource) { path = pathStack.pop(); if (objectSource.isPresent()) { Record completedRecord = currentRecordBuilder.build(); valueStack.push(new CacheReference(completedRecord.key())); dependentKeys.add(completedRecord.key()); recordSet.merge(completedRecord); } currentRecordBuilder = recordStack.pop().toBuilder(); }
/** * Clear all entries from the normalized cache. This is asynchronous operation and will be scheduled on the * dispatcher * * @param callback to be notified when operation is completed */ public void clearNormalizedCache(@NotNull ApolloStoreOperation.Callback<Boolean> callback) { checkNotNull(callback, "callback == null"); apolloStore.clearAll().enqueue(callback); }
public final NormalizedCache createChain(final RecordFieldJsonAdapter recordFieldAdapter) { if (nextFactory.isPresent()) { return create(recordFieldAdapter) .chain(nextFactory.map(new Function<NormalizedCacheFactory, NormalizedCache>() { @NotNull @Override public NormalizedCache apply(@NotNull NormalizedCacheFactory factory) { return factory.createChain(recordFieldAdapter); } }).get()); } else { return create(recordFieldAdapter); } }
@Override public void run() { try { apolloStore.rollbackOptimisticUpdatesAndPublish(request.uniqueId).execute(); } catch (Exception e) { logger.e(e, "failed to rollback operation optimistic updates, for: %s", request.operation); } } });
Set<String> rollbackOptimisticUpdates(final InterceptorRequest request) { try { return apolloStore.rollbackOptimisticUpdates(request.uniqueId).execute(); } catch (Exception e) { logger.e(e, "failed to rollback operation optimistic updates, for: %s", request.operation); return Collections.emptySet(); } }
@Override public void run() { try { if (request.optimisticUpdates.isPresent()) { Operation.Data optimisticUpdates = request.optimisticUpdates.get(); apolloStore.writeOptimisticUpdatesAndPublish(request.operation, optimisticUpdates, request.uniqueId) .execute(); } } catch (Exception e) { logger.e(e, "failed to write operation optimistic updates, for: %s", request.operation); } } });
public Record build() { return new Record(key, fields, mutationId); } }
public Collection<Record> records() { return recordSet.allRecords(); }
@Override public void subscribe(final SingleEmitter<T> emitter) { operation.enqueue(new ApolloStoreOperation.Callback<T>() { @Override public void onSuccess(T result) { emitter.onSuccess(result); } @Override public void onFailure(Throwable t) { emitter.onError(t); } }); } });
public static RecordFieldJsonAdapter create() { return new RecordFieldJsonAdapter(); }
@Override public void run() { T result; try { result = perform(); } catch (Exception e) { notifyFailure(new ApolloException("Failed to perform store operation", e)); return; } notifySuccess(result); } });
@Override public void enqueue(Callback<T> callback) { if (callback != null) { callback.onSuccess(result); } } };
@Test public void testClearSecondaryCache() { LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION); NormalizedCache primaryCache = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION) .chain(secondaryCacheFactory).createChain(basicFieldAdapter); Record record = Record.builder("key").build(); primaryCache.merge(record, CacheHeaders.NONE); primaryCache.nextCache().get().clearAll(); assertThat(primaryCache.nextCache().get().loadRecord("key", CacheHeaders.NONE)).isNull(); }