void willResolveRecord(CacheKey cacheKey) { pathStack = new SimpleStack<>(); recordStack = new SimpleStack<>(); valueStack = new SimpleStack<>(); dependentKeys = new HashSet<>(); path = new ArrayList<>(); currentRecordBuilder = Record.builder(cacheKey.key()); recordSet = new RecordSet(); }
@Nullable @Override public F execute(ReadableStore cache) { Record rootRecord = cache.read(cacheKey.key(), CacheHeaders.NONE); if (rootRecord == null) { return null; } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, variables, cacheKeyResolver(), CacheHeaders.NONE, cacheKeyBuilder); //noinspection unchecked RealResponseReader<Record> responseReader = new RealResponseReader<>(variables, rootRecord, fieldValueResolver, scalarTypeAdapters, ResponseNormalizer.NO_OP_NORMALIZER); return responseFieldMapper.map(responseReader); } });
@Override public void willResolveObject(ResponseField field, Optional<R> objectSource) { pathStack.push(path); CacheKey cacheKey = objectSource.isPresent() ? resolveCacheKey(field, objectSource.get()) : CacheKey.NO_KEY; String cacheKeyValue = cacheKey.key(); if (cacheKey.equals(CacheKey.NO_KEY)) { cacheKeyValue = pathToString(); } else { path = new ArrayList<>(); path.add(cacheKeyValue); } recordStack.push(currentRecordBuilder.build()); currentRecordBuilder = Record.builder(cacheKeyValue); }
@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; }
private Record valueForObject(Record record, ResponseField field) { CacheReference cacheReference; CacheKey fieldCacheKey = cacheKeyResolver.fromFieldArguments(field, variables); if (!fieldCacheKey.equals(CacheKey.NO_KEY)) { cacheReference = new CacheReference(fieldCacheKey.key()); } else { cacheReference = fieldValue(record, field); } if (cacheReference != null) { Record referencedRecord = readableCache.read(cacheReference.key(), cacheHeaders); if (referencedRecord == null) { // we are unable to find record in the cache by reference, // means it was removed intentionally by using imperative store API or // evicted from LRU cache, we must prevent of further resolving cache response as it's broken throw new IllegalStateException("Cache MISS: failed to find record in cache by reference"); } return referencedRecord; } return null; }
@Nullable @Override public T execute(ReadableStore cache) { Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), CacheHeaders.NONE); if (rootRecord == null) { return null; } ResponseFieldMapper<D> responseFieldMapper = operation.responseFieldMapper(); CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(), cacheKeyResolver(), CacheHeaders.NONE, cacheKeyBuilder); //noinspection unchecked RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord, fieldValueResolver, scalarTypeAdapters, ResponseNormalizer.NO_OP_NORMALIZER); return operation.wrapData(responseFieldMapper.map(responseReader)); } });
@NotNull @Override public Response<T> execute(ReadableStore cache) { Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), cacheHeaders); if (rootRecord == null) { return Response.<T>builder(operation).fromCache(true).build(); } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(), cacheKeyResolver(), cacheHeaders, cacheKeyBuilder); RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord, fieldValueResolver, scalarTypeAdapters, responseNormalizer); try { responseNormalizer.willResolveRootQuery(operation); T data = operation.wrapData(responseFieldMapper.map(responseReader)); return Response.<T>builder(operation) .data(data) .fromCache(true) .dependentKeys(responseNormalizer.dependentKeys()) .build(); } catch (Exception e) { logger.e(e, "Failed to read cache response"); return Response.<T>builder(operation).fromCache(true).build(); } } });
@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; }
void willResolveRecord(CacheKey cacheKey) { pathStack = new SimpleStack<>(); recordStack = new SimpleStack<>(); valueStack = new SimpleStack<>(); dependentKeys = new HashSet<>(); path = new ArrayList<>(); currentRecordBuilder = Record.builder(cacheKey.key()); recordSet = new RecordSet(); }
void willResolveRecord(CacheKey cacheKey) { pathStack = new SimpleStack<>(); recordStack = new SimpleStack<>(); valueStack = new SimpleStack<>(); dependentKeys = new HashSet<>(); path = new ArrayList<>(); currentRecordBuilder = Record.builder(cacheKey.key()); recordSet = new RecordSet(); }
@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); return result | deleteRecord(cacheKey.key()); }
@Nullable @Override public F execute(ReadableStore cache) { Record rootRecord = cache.read(cacheKey.key(), CacheHeaders.NONE); if (rootRecord == null) { return null; } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, variables, cacheKeyResolver(), CacheHeaders.NONE); //noinspection unchecked RealResponseReader<Record> responseReader = new RealResponseReader<>(variables, rootRecord, fieldValueResolver, scalarTypeAdapters, ResponseNormalizer.NO_OP_NORMALIZER); return responseFieldMapper.map(responseReader); } });
@Nullable @Override public F execute(ReadableStore cache) { Record rootRecord = cache.read(cacheKey.key(), CacheHeaders.NONE); if (rootRecord == null) { return null; } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, variables, cacheKeyResolver(), CacheHeaders.NONE); //noinspection unchecked RealResponseReader<Record> responseReader = new RealResponseReader<>(variables, rootRecord, fieldValueResolver, scalarTypeAdapters, ResponseNormalizer.NO_OP_NORMALIZER); return responseFieldMapper.map(responseReader); } });
@Override public void willResolveObject(ResponseField field, Optional<R> objectSource) { pathStack.push(path); CacheKey cacheKey = objectSource.isPresent() ? resolveCacheKey(field, objectSource.get()) : CacheKey.NO_KEY; String cacheKeyValue = cacheKey.key(); if (cacheKey == CacheKey.NO_KEY) { cacheKeyValue = pathToString(); } else { path = new ArrayList<>(); path.add(cacheKeyValue); } recordStack.push(currentRecordBuilder.build()); currentRecordBuilder = Record.builder(cacheKeyValue); }
@Override public void willResolveObject(ResponseField field, Optional<R> objectSource) { pathStack.push(path); CacheKey cacheKey = objectSource.isPresent() ? resolveCacheKey(field, objectSource.get()) : CacheKey.NO_KEY; String cacheKeyValue = cacheKey.key(); if (cacheKey == CacheKey.NO_KEY) { cacheKeyValue = pathToString(); } else { path = new ArrayList<>(); path.add(cacheKeyValue); } recordStack.push(currentRecordBuilder.build()); currentRecordBuilder = Record.builder(cacheKeyValue); }
@Nullable @Override public T execute(ReadableStore cache) { Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), CacheHeaders.NONE); if (rootRecord == null) { return null; } ResponseFieldMapper<D> responseFieldMapper = operation.responseFieldMapper(); CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(), cacheKeyResolver(), CacheHeaders.NONE); //noinspection unchecked RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord, fieldValueResolver, scalarTypeAdapters, ResponseNormalizer.NO_OP_NORMALIZER); return operation.wrapData(responseFieldMapper.map(responseReader)); } });