use of com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory in project apollo-android by apollographql.
the class NormalizedCacheTestCase method setUp.
@Before
public void setUp() {
OkHttpClient okHttpClient = new OkHttpClient.Builder().writeTimeout(2, TimeUnit.SECONDS).readTimeout(2, TimeUnit.SECONDS).dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).dispatcher(Utils.immediateExecutor()).build();
}
use of com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory in project apollo-android by apollographql.
the class Rx2ApolloTest method setup.
@Before
public void setup() {
OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(immediateExecutorService())).build();
apolloClient = ApolloClient.builder().serverUrl(server.url("/")).dispatcher(immediateExecutor()).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).build();
}
use of com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory in project apollo-android by apollographql.
the class BaseFetcherTest method setUp.
@Before
public void setUp() {
server = new MockWebServer();
OkHttpClient okHttpClient = new OkHttpClient.Builder().writeTimeout(2, TimeUnit.SECONDS).readTimeout(2, TimeUnit.SECONDS).dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).dispatcher(Utils.immediateExecutor()).build();
}
use of com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory in project apollo-android by apollographql.
the class GitHuntApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
ApolloSqlHelper apolloSqlHelper = new ApolloSqlHelper(this, SQL_CACHE_NAME);
NormalizedCacheFactory normalizedCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION).chain(new SqlNormalizedCacheFactory(apolloSqlHelper));
CacheKeyResolver cacheKeyResolver = new CacheKeyResolver() {
@Nonnull
@Override
public CacheKey fromFieldRecordSet(@Nonnull ResponseField field, @Nonnull Map<String, Object> recordSet) {
String typeName = (String) recordSet.get("__typename");
if ("User".equals(typeName)) {
String userKey = typeName + "." + recordSet.get("login");
return CacheKey.from(userKey);
}
if (recordSet.containsKey("id")) {
String typeNameAndIDKey = recordSet.get("__typename") + "." + recordSet.get("id");
return CacheKey.from(typeNameAndIDKey);
}
return CacheKey.NO_KEY;
}
// Use this resolver to customize the key for fields with variables: eg entry(repoFullName: $repoFullName).
// This is useful if you want to make query to be able to resolved, even if it has never been run before.
@Nonnull
@Override
public CacheKey fromFieldArguments(@Nonnull ResponseField field, @Nonnull Operation.Variables variables) {
return CacheKey.NO_KEY;
}
};
apolloClient = ApolloClient.builder().serverUrl(BASE_URL).okHttpClient(okHttpClient).normalizedCache(normalizedCacheFactory, cacheKeyResolver).subscriptionTransportFactory(new WebSocketSubscriptionTransport.Factory(SUBSCRIPTION_BASE_URL, okHttpClient)).build();
}
use of com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory in project apollo-android by apollographql.
the class AsyncNormalizedCacheTestCase method setUp.
@Before
public void setUp() {
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).build();
}
Aggregations