use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testDualCacheMultipleRecord.
@Test
public void testDualCacheMultipleRecord() {
LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
NormalizedCache primaryCache = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
Record.Builder recordBuilder = Record.builder("root1");
recordBuilder.addField("bar", "bar");
final Record record1 = recordBuilder.build();
recordBuilder = Record.builder("root2");
recordBuilder.addField("bar", "bar");
final Record record2 = recordBuilder.build();
recordBuilder = Record.builder("root3");
recordBuilder.addField("bar", "bar");
final Record record3 = recordBuilder.build();
Collection<Record> records = Arrays.asList(record1, record2, record3);
Collection<String> keys = Arrays.asList(record1.key(), record2.key(), record3.key());
primaryCache.merge(records, CacheHeaders.NONE);
assertThat(primaryCache.loadRecords(keys, CacheHeaders.NONE).size()).isEqualTo(3);
// verify write through behavior
assertThat(primaryCache.loadRecords(keys, CacheHeaders.NONE).size()).isEqualTo(3);
assertThat(primaryCache.nextCache().get().loadRecords(keys, CacheHeaders.NONE).size()).isEqualTo(3);
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testHeader_noCache.
@Test
public void testHeader_noCache() {
LruNormalizedCache lruCache = new LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024).build()).create(basicFieldAdapter);
Record testRecord = createTestRecord("1");
lruCache.merge(testRecord, CacheHeaders.builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "true").build());
final Record record = lruCache.loadRecord("key1", CacheHeaders.NONE);
assertThat(record).isNull();
Record testRecord1 = createTestRecord("1");
Record testRecord2 = createTestRecord("2");
Collection<Record> testRecordSet = new HashSet<>();
testRecordSet.add(testRecord1);
testRecordSet.add(testRecord2);
lruCache.merge(testRecordSet, CacheHeaders.builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "true").build());
final Record record1 = lruCache.loadRecord("key1", CacheHeaders.NONE);
final Record record2 = lruCache.loadRecord("key2", CacheHeaders.NONE);
assertThat(record1).isNull();
assertThat(record2).isNull();
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testClearPrimaryCache.
@Test
public void testClearPrimaryCache() {
LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
LruNormalizedCache primaryCache = (LruNormalizedCache) new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
Record record = Record.builder("key").build();
primaryCache.merge(record, CacheHeaders.NONE);
primaryCache.clearCurrentCache();
assertThat(primaryCache.nextCache().get().loadRecord("key", CacheHeaders.NONE)).isNotNull();
assertThat(primaryCache.nextCache().get().loadRecord("key", CacheHeaders.NONE)).isNotNull();
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testLoad_recordNotPresent.
@Test
public void testLoad_recordNotPresent() {
LruNormalizedCache lruCache = new LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024).build()).create(basicFieldAdapter);
final Record record = lruCache.loadRecord("key1", CacheHeaders.NONE);
assertThat(record).isNull();
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testSaveAndLoad_multipleRecord_readMultiple.
@Test
public void testSaveAndLoad_multipleRecord_readMultiple() {
LruNormalizedCache lruCache = new LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024).build()).create(basicFieldAdapter);
Record testRecord1 = createTestRecord("1");
Record testRecord2 = createTestRecord("2");
Record testRecord3 = createTestRecord("3");
List<Record> inputRecords = Arrays.asList(testRecord1, testRecord2, testRecord3);
lruCache.merge(inputRecords, CacheHeaders.NONE);
final Collection<Record> readRecords = lruCache.loadRecords(Arrays.asList("key1", "key2", "key3"), CacheHeaders.NONE);
// noinspection ResultOfMethodCallIgnored
assertThat(readRecords).containsExactlyElementsIn(inputRecords);
}
Aggregations