public static CacheReference deserialize(String serializedCacheReference) { Matcher matcher = SERIALIZATION_REGEX_PATTERN.matcher(serializedCacheReference); if (!matcher.find() || matcher.groupCount() != 1) { throw new IllegalArgumentException("Not a cache reference: " + serializedCacheReference + " Must be of the form:" + SERIALIZATION_TEMPLATE); } return new CacheReference(matcher.group(1)); }
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; }
@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(); }
@Test public void testRecordWeigher() { Record.Builder recordBuilder = Record.builder("root"); BigDecimal expectedBigDecimal = new BigDecimal(1.23); String expectedStringValue = "StringValue"; Boolean expectedBooleanValue = true; CacheReference expectedCacheReference = new CacheReference("foo"); List<CacheReference> expectedCacheReferenceList = Arrays.asList(new CacheReference("bar"), new CacheReference ("baz")); List<Object> expectedScalarList = Arrays.<Object>asList("scalarOne", "scalarTwo"); recordBuilder.addField("bigDecimal", expectedBigDecimal); recordBuilder.addField("string", expectedStringValue); recordBuilder.addField("boolean", expectedBooleanValue); recordBuilder.addField("cacheReference", expectedCacheReference); recordBuilder.addField("scalarList", expectedScalarList); recordBuilder.addField("referenceList", expectedCacheReferenceList); Record record = recordBuilder.build(); record.sizeEstimateBytes(); //It's difficult to say what the "right" size estimate is, so just checking it is has been calculate at all. assertThat(record.sizeEstimateBytes()).isNotEqualTo(-1); } }
String expectedStringValue = "StringValue"; Boolean expectedBooleanValue = true; CacheReference expectedCacheReference = new CacheReference("foo"); List<CacheReference> expectedCacheReferenceList = Arrays.asList(new CacheReference("bar"), new CacheReference("baz")); List<Object> expectedScalarList = Arrays.<Object>asList("scalarOne", "scalarTwo"); List<List<String>> expectedListOfScalarList = Arrays.asList(Arrays.asList("scalarOne", "scalarTwo"));
public static CacheReference deserialize(String serializedCacheReference) { Matcher matcher = SERIALIZATION_REGEX_PATTERN.matcher(serializedCacheReference); if (!matcher.find() || matcher.groupCount() != 1) { throw new IllegalArgumentException("Not a cache reference: " + serializedCacheReference + " Must be of the form:" + SERIALIZATION_TEMPLATE); } return new CacheReference(matcher.group(1)); }
public static CacheReference deserialize(String serializedCacheReference) { Matcher matcher = SERIALIZATION_REGEX_PATTERN.matcher(serializedCacheReference); if (!matcher.find() || matcher.groupCount() != 1) { throw new IllegalArgumentException("Not a cache reference: " + serializedCacheReference + " Must be of the form:" + SERIALIZATION_TEMPLATE); } return new CacheReference(matcher.group(1)); }
private Record valueForObject(Record record, ResponseField field) { CacheReference cacheReference; CacheKey fieldCacheKey = cacheKeyResolver.fromFieldArguments(field, variables); if (fieldCacheKey != 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; }
private Record valueForObject(Record record, ResponseField field) { CacheReference cacheReference; CacheKey fieldCacheKey = cacheKeyResolver.fromFieldArguments(field, variables); if (fieldCacheKey != 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; }
@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(); }
@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(); }