use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testClearAll.
@Test
public void testClearAll() {
LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
NormalizedCache primaryCacheStore = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
Record record = Record.builder("key").build();
primaryCacheStore.merge(record, CacheHeaders.NONE);
primaryCacheStore.clearAll();
assertThat(primaryCacheStore.loadRecord("key", CacheHeaders.NONE)).isNull();
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method assertTestRecordPresentAndAccurate.
private void assertTestRecordPresentAndAccurate(Record testRecord, NormalizedCache store) {
final Record cacheRecord1 = store.loadRecord(testRecord.key(), CacheHeaders.NONE);
assertThat(cacheRecord1.key()).isEqualTo(testRecord.key());
assertThat(cacheRecord1.field("a")).isEqualTo(testRecord.field("a"));
assertThat(cacheRecord1.field("b")).isEqualTo(testRecord.field("b"));
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testClearSecondaryCache.
@Test
public void testClearSecondaryCache() {
LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
NormalizedCache primaryCache = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(secondaryCacheFactory).createChain(basicFieldAdapter);
Record record = Record.builder("key").build();
primaryCache.merge(record, CacheHeaders.NONE);
primaryCache.nextCache().get().clearAll();
assertThat(primaryCache.nextCache().get().loadRecord("key", CacheHeaders.NONE)).isNull();
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class LruNormalizedCacheTest method testSaveAndLoad_multipleRecord_readSingle.
@Test
public void testSaveAndLoad_multipleRecord_readSingle() {
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> records = Arrays.asList(testRecord1, testRecord2, testRecord3);
lruCache.merge(records, CacheHeaders.NONE);
assertTestRecordPresentAndAccurate(testRecord1, lruCache);
assertTestRecordPresentAndAccurate(testRecord2, lruCache);
assertTestRecordPresentAndAccurate(testRecord3, lruCache);
}
use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.
the class SqlNormalizedCacheTest method testHeader_noCache.
@Test
public void testHeader_noCache() {
sqlStore.merge(Record.builder(STANDARD_KEY).build(), CacheHeaders.builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "true").build());
final Record record = sqlStore.loadRecord(STANDARD_KEY, CacheHeaders.NONE);
assertThat(record).isNull();
}
Aggregations