@NotNull public Set<String> mergeOptimisticUpdate(@NotNull final Record record) { checkNotNull(record, "record == null"); final RecordJournal journal = lruCache.getIfPresent(record.key()); if (journal == null) { lruCache.put(record.key(), new RecordJournal(record)); return Collections.singleton(record.key()); } else { return journal.commit(record); } }
@NotNull protected Set<String> performMerge(@NotNull final Record apolloRecord, @NotNull final CacheHeaders cacheHeaders) { final Record oldRecord = lruCache.getIfPresent(apolloRecord.key()); if (oldRecord == null) { lruCache.put(apolloRecord.key(), apolloRecord); return apolloRecord.keys(); } else { Set<String> changedKeys = oldRecord.mergeWith(apolloRecord); //re-insert to trigger new weight calculation lruCache.put(apolloRecord.key(), oldRecord); return changedKeys; } }
@Nullable @Override public Record loadRecord(@NotNull final String key, @NotNull final CacheHeaders cacheHeaders) { checkNotNull(key, "key == null"); checkNotNull(cacheHeaders, "cacheHeaders == null"); try { final Optional<Record> nonOptimisticRecord = nextCache() .flatMap(new Function<NormalizedCache, Optional<Record>>() { @NotNull @Override public Optional<Record> apply(@NotNull NormalizedCache cache) { return Optional.fromNullable(cache.loadRecord(key, cacheHeaders)); } }); final RecordJournal journal = lruCache.getIfPresent(key); if (journal != null) { return nonOptimisticRecord.map(new Function<Record, Record>() { @NotNull @Override public Record apply(@NotNull Record record) { Record result = record.clone(); result.mergeWith(journal.snapshot); return result; } }).or(journal.snapshot.clone()); } else { return nonOptimisticRecord.orNull(); } } catch (Exception ignore) { return null; } }
@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 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; }
@Nonnull @Override public Observable<Raw> read(@Nonnull Key key) { Observable<Raw> cachedValue = networkResponses.getIfPresent(key); return cachedValue == null ? Observable.error(new FileNotFoundException()) : cachedValue; }
@Nonnull @Override public Observable<Parsed> memory(@Nonnull Key key) { Observable<Parsed> cachedValue = memCache.getIfPresent(key); return cachedValue == null ? Observable.<Parsed>empty() : cachedValue; }
/** * @since 11.0 */ @Nullable @Override public V getIfPresent(Object key) { return delegate().getIfPresent(key); }
@Nonnull public Set<String> mergeOptimisticUpdate(@Nonnull final Record record) { checkNotNull(record, "record == null"); final RecordJournal journal = lruCache.getIfPresent(record.key()); if (journal == null) { lruCache.put(record.key(), new RecordJournal(record)); return Collections.singleton(record.key()); } else { return journal.commit(record); } }
@Nonnull public Set<String> mergeOptimisticUpdate(@Nonnull final Record record) { checkNotNull(record, "record == null"); final RecordJournal journal = lruCache.getIfPresent(record.key()); if (journal == null) { lruCache.put(record.key(), new RecordJournal(record)); return Collections.singleton(record.key()); } else { return journal.commit(record); } }
@Nonnull @Override public Set<String> merge(@Nonnull final Record apolloRecord, @Nonnull final CacheHeaders cacheHeaders) { if (cacheHeaders.hasHeader(GraphQLCacheHeaders.DO_NOT_STORE)) { return Collections.emptySet(); } //noinspection ResultOfMethodCallIgnored nextCache().apply(new Action<NormalizedCache>() { @Override public void apply(@Nonnull NormalizedCache cache) { cache.merge(apolloRecord, cacheHeaders); } }); final Record oldRecord = lruCache.getIfPresent(apolloRecord.key()); if (oldRecord == null) { lruCache.put(apolloRecord.key(), apolloRecord); return Collections.emptySet(); } else { Set<String> changedKeys = oldRecord.mergeWith(apolloRecord); //re-insert to trigger new weight calculation lruCache.put(apolloRecord.key(), oldRecord); return changedKeys; } }
@Nonnull @Override public Set<String> merge(@Nonnull final Record apolloRecord, @Nonnull final CacheHeaders cacheHeaders) { if (cacheHeaders.hasHeader(GraphQLCacheHeaders.DO_NOT_STORE)) { return Collections.emptySet(); } //noinspection ResultOfMethodCallIgnored nextCache().apply(new Action<NormalizedCache>() { @Override public void apply(@Nonnull NormalizedCache cache) { cache.merge(apolloRecord, cacheHeaders); } }); final Record oldRecord = lruCache.getIfPresent(apolloRecord.key()); if (oldRecord == null) { lruCache.put(apolloRecord.key(), apolloRecord); return Collections.emptySet(); } else { Set<String> changedKeys = oldRecord.mergeWith(apolloRecord); //re-insert to trigger new weight calculation lruCache.put(apolloRecord.key(), oldRecord); return changedKeys; } }
@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 = 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; }
@Nullable @Override public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) { checkNotNull(key, "key == null"); checkNotNull(cacheHeaders, "cacheHeaders == null"); try { final Optional<Record> nonOptimisticRecord = nextCache() .flatMap(new Function<NormalizedCache, Optional<Record>>() { @Nonnull @Override public Optional<Record> apply(@Nonnull NormalizedCache cache) { return Optional.fromNullable(cache.loadRecord(key, cacheHeaders)); } }); final RecordJournal journal = lruCache.getIfPresent(key); if (journal != null) { return nonOptimisticRecord.map(new Function<Record, Record>() { @Nonnull @Override public Record apply(@Nonnull Record record) { Record result = record.clone(); result.mergeWith(journal.snapshot); return result; } }).or(journal.snapshot.clone()); } else { return nonOptimisticRecord.orNull(); } } catch (Exception ignore) { return null; } }
@Nullable @Override public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) { checkNotNull(key, "key == null"); checkNotNull(cacheHeaders, "cacheHeaders == null"); try { final Optional<Record> nonOptimisticRecord = nextCache() .flatMap(new Function<NormalizedCache, Optional<Record>>() { @Nonnull @Override public Optional<Record> apply(@Nonnull NormalizedCache cache) { return Optional.fromNullable(cache.loadRecord(key, cacheHeaders)); } }); final RecordJournal journal = lruCache.getIfPresent(key); if (journal != null) { return nonOptimisticRecord.map(new Function<Record, Record>() { @Nonnull @Override public Record apply(@Nonnull Record record) { Record result = record.clone(); result.mergeWith(journal.snapshot); return result; } }).or(journal.snapshot.clone()); } else { return nonOptimisticRecord.orNull(); } } catch (Exception ignore) { return null; } }