Search in sources :

Example 1 with HttpCache

use of com.apollographql.apollo.api.cache.http.HttpCache in project apollo-android by apollographql.

the class HttpCacheTest method setUp.

@Before
public void setUp() {
    CustomTypeAdapter<Date> dateCustomTypeAdapter = new CustomTypeAdapter<Date>() {

        @Override
        public Date decode(CustomTypeValue value) {
            try {
                return DATE_FORMAT.parse(value.value.toString());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public CustomTypeValue encode(Date value) {
            return new CustomTypeValue.GraphQLString(DATE_FORMAT.format(value));
        }
    };
    cacheStore = new MockHttpCacheStore();
    cacheStore.delegate = new DiskLruHttpCacheStore(inMemoryFileSystem, new File("/cache/"), Integer.MAX_VALUE);
    HttpCache cache = new ApolloHttpCache(cacheStore, null);
    okHttpClient = new OkHttpClient.Builder().addInterceptor(new TrackingInterceptor()).addInterceptor(cache.interceptor()).dispatcher(new Dispatcher(Utils.immediateExecutorService())).readTimeout(2, TimeUnit.SECONDS).writeTimeout(2, TimeUnit.SECONDS).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).dispatcher(Utils.immediateExecutor()).addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter).httpCache(cache).build();
}
Also used : ApolloHttpCache(com.apollographql.apollo.cache.http.ApolloHttpCache) OkHttpClient(okhttp3.OkHttpClient) ApolloHttpCache(com.apollographql.apollo.cache.http.ApolloHttpCache) HttpCache(com.apollographql.apollo.api.cache.http.HttpCache) Dispatcher(okhttp3.Dispatcher) Date(java.util.Date) CustomTypeAdapter(com.apollographql.apollo.response.CustomTypeAdapter) CustomTypeValue(com.apollographql.apollo.response.CustomTypeValue) DiskLruHttpCacheStore(com.apollographql.apollo.cache.http.DiskLruHttpCacheStore) ParseException(java.text.ParseException) File(java.io.File) Before(org.junit.Before)

Aggregations

HttpCache (com.apollographql.apollo.api.cache.http.HttpCache)1 ApolloHttpCache (com.apollographql.apollo.cache.http.ApolloHttpCache)1 DiskLruHttpCacheStore (com.apollographql.apollo.cache.http.DiskLruHttpCacheStore)1 CustomTypeAdapter (com.apollographql.apollo.response.CustomTypeAdapter)1 CustomTypeValue (com.apollographql.apollo.response.CustomTypeValue)1 File (java.io.File)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Dispatcher (okhttp3.Dispatcher)1 OkHttpClient (okhttp3.OkHttpClient)1 Before (org.junit.Before)1