Java Code Examples for okhttp3.OkHttpClient.Builder#cache()

The following examples show how to use okhttp3.OkHttpClient.Builder#cache() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, GitlabSession.class, session.id());
	GitlabInterceptor interceptors = new GitlabInterceptor(session);
	String baseurl = GitlabPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new GitlabCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = GitlabPagination.get();
}
 
Example 2
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, GitlabSession.class, session.id());
	GitlabInterceptor interceptors = new GitlabInterceptor(session);
	String baseurl = GitlabPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new GitlabCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = GitlabPagination.get();
}
 
Example 3
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, StackExchangeSession.class, session.id());
	StackExchangeInterceptor interceptors = new StackExchangeInterceptor(session);
	String baseurl = StackExchangePropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new StackExchangeCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = StackExchangePagination.get();
}
 
Example 4
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, StackExchangeSession.class, session.id());
	StackExchangeInterceptor interceptors = new StackExchangeInterceptor(session);
	String baseurl = StackExchangePropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new StackExchangeCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = StackExchangePagination.get();
}
 
Example 5
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, BitbucketSession.class, session.id());
	BitbucketInterceptor interceptors = new BitbucketInterceptor(session);
	String baseurl = BitbucketPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new BitbucketCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = BitbucketPagination.get();
}
 
Example 6
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, BitbucketSession.class, session.id());
	BitbucketInterceptor interceptors = new BitbucketInterceptor(session);
	String baseurl = BitbucketPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new BitbucketCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = BitbucketPagination.get();
}
 
Example 7
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, GitHubSession.class, session.id());
	GitHubInterceptor interceptors = new GitHubInterceptor(session);
	String baseurl = GitHubPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/"))
		baseurl += "/"; // FIXME Validate in Model with EVL

	Builder clientBuilder = AbstractClient.okHttp(executor);

	ICache localcache = new GitHubCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}

	// FIXME update generator
	clientBuilder = clientBuilder
			.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));

	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = GitHubSearchAPIPagination.get();
}
 
Example 8
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, GitHubSession.class, session.id());
	GitHubInterceptor interceptors = new GitHubInterceptor(session);
	String baseurl = GitHubPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/"))
		baseurl += "/"; // FIXME Validate in Model with EVL

	Builder clientBuilder = AbstractClient.okHttp(executor);

	ICache localcache = new GitHubCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()){
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");	
	}

	clientBuilder = clientBuilder
			.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));

	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = GitHubEntityAPIPagination.get();
}