@Nullable @Override public Record loadRecord(@NotNull final String key, @NotNull final CacheHeaders cacheHeaders) { final Record record; try { record = lruCache.get(key, new Callable<Record>() { @Override public Record call() throws Exception { return nextCache().flatMap(new Function<NormalizedCache, Optional<Record>>() { @NotNull @Override public Optional<Record> apply(@NotNull NormalizedCache cache) { return Optional.fromNullable(cache.loadRecord(key, cacheHeaders)); } }).get(); // lruCache.get(key, callable) requires non-null. } }); } catch (Exception ignore) { return null; } if (cacheHeaders.hasHeader(ApolloCacheHeaders.EVICT_AFTER_READ)) { lruCache.invalidate(key); } return record; }
@Override public boolean remove(@NotNull final CacheKey cacheKey, final boolean cascade) { checkNotNull(cacheKey, "cacheKey == null"); boolean result = nextCache().map(new Function<NormalizedCache, Boolean>() { @NotNull @Override public Boolean apply(@NotNull NormalizedCache cache) { return cache.remove(cacheKey, cascade); } }).or(Boolean.FALSE); RecordJournal recordJournal = lruCache.getIfPresent(cacheKey.key()); if (recordJournal != null) { lruCache.invalidate(cacheKey.key()); result = true; if (cascade) { for (CacheReference cacheReference : recordJournal.snapshot.referencedFields()) { result = result & remove(CacheKey.from(cacheReference.key()), true); } } } return result; }
@Override public boolean remove(@NotNull final CacheKey cacheKey, final boolean cascade) { checkNotNull(cacheKey, "cacheKey == null"); boolean result; result = nextCache().map(new Function<NormalizedCache, Boolean>() { @NotNull @Override public Boolean apply(@NotNull NormalizedCache cache) { return cache.remove(cacheKey, cascade); } }).or(Boolean.FALSE); Record record = lruCache.getIfPresent(cacheKey.key()); if (record != null) { lruCache.invalidate(cacheKey.key()); result = true; if (cascade) { for (CacheReference cacheReference : record.referencedFields()) { result = result & remove(CacheKey.from(cacheReference.key()), true); } } } return result; }
@Override public void clear(@Nonnull Key key) { networkResponses.invalidate(key); }
@Override public void invalidate(Object key) { delegate().invalidate(key); }
@Override public void clear(@Nonnull Key key) { inFlightRequests.invalidate(key); memCache.invalidate(key); StoreUtil.clearPersister(persister(), key); notifyRefresh(key); }
@Nullable @Override public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) { final Record record; try { record = lruCache.get(key, new Callable<Record>() { @Override public Record call() throws Exception { return nextCache().flatMap(new Function<NormalizedCache, Optional<Record>>() { @Nonnull @Override public Optional<Record> apply(@Nonnull NormalizedCache cache) { return Optional.fromNullable(cache.loadRecord(key, cacheHeaders)); } }).get(); // lruCache.get(key, callable) requires non-null. } }); } catch (Exception ignore) { return null; } if (cacheHeaders.hasHeader(GraphQLCacheHeaders.EVICT_AFTER_READ)) { lruCache.invalidate(key); } return record; }
@Nullable @Override public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) { final Record record; try { record = lruCache.get(key, new Callable<Record>() { @Override public Record call() throws Exception { return nextCache().flatMap(new Function<NormalizedCache, Optional<Record>>() { @Nonnull @Override public Optional<Record> apply(@Nonnull NormalizedCache cache) { return Optional.fromNullable(cache.loadRecord(key, cacheHeaders)); } }).get(); // lruCache.get(key, callable) requires non-null. } }); } catch (Exception ignore) { return null; } if (cacheHeaders.hasHeader(GraphQLCacheHeaders.EVICT_AFTER_READ)) { lruCache.invalidate(key); } return record; }
@Nonnull Observable<Parsed> response(@Nonnull final Key key) { return fetcher() .fetch(key) .flatMap(raw -> persister() .write(key, raw) .flatMap(aBoolean -> readDisk(key))) .onErrorReturn(throwable -> { if (stalePolicy == StalePolicy.NETWORK_BEFORE_STALE) { return readDisk(key, throwable).toBlocking().first(); } throw Exceptions.propagate(throwable); }) .doOnNext(this::notifySubscribers) .doOnTerminate(() -> inFlightRequests.invalidate(key)) .cache(); }
@Override public boolean remove(@Nonnull final CacheKey cacheKey) { checkNotNull(cacheKey, "cacheKey == null"); boolean result = nextCache().map(new Function<NormalizedCache, Boolean>() { @Nonnull @Override public Boolean apply(@Nonnull NormalizedCache cache) { return cache.remove(cacheKey); } }).or(Boolean.FALSE); if (lruCache.getIfPresent(cacheKey.key()) != null) { lruCache.invalidate(cacheKey.key()); result = true; } return result; }
@Override public boolean remove(@Nonnull final CacheKey cacheKey) { checkNotNull(cacheKey, "cacheKey == null"); boolean result = nextCache().map(new Function<NormalizedCache, Boolean>() { @Nonnull @Override public Boolean apply(@Nonnull NormalizedCache cache) { return cache.remove(cacheKey); } }).or(Boolean.FALSE); if (lruCache.getIfPresent(cacheKey.key()) != null) { lruCache.invalidate(cacheKey.key()); result = true; } return result; }
@Override public boolean remove(@Nonnull final CacheKey cacheKey) { checkNotNull(cacheKey, "cacheKey == null"); boolean result; result = nextCache().map(new Function<NormalizedCache, Boolean>() { @Nonnull @Override public Boolean apply(@Nonnull NormalizedCache cache) { return cache.remove(cacheKey); } }).or(Boolean.FALSE); if (lruCache.getIfPresent(cacheKey.key()) != null) { lruCache.invalidate(cacheKey.key()); result = true; } return result; }
@Override public boolean remove(@Nonnull final CacheKey cacheKey) { checkNotNull(cacheKey, "cacheKey == null"); boolean result; result = nextCache().map(new Function<NormalizedCache, Boolean>() { @Nonnull @Override public Boolean apply(@Nonnull NormalizedCache cache) { return cache.remove(cacheKey); } }).or(Boolean.FALSE); if (lruCache.getIfPresent(cacheKey.key()) != null) { lruCache.invalidate(cacheKey.key()); result = true; } return result; }