Am正在苦苦挣扎的问题之一,需要花费近10分钟才能反映出最新的结果。实际上,在使用类型为Get的API时,服务的结构如下:
www.abc.net/wp-json/wp/v2/posts?categories=192&page=1&per_page=2
当我尝试从浏览器调用该服务时,它会显示更新的信息,但是当我尝试通过改造从我的android应用程序中调用该服务时,会将更新的响应延迟近10分钟。
Here是我上一个问题中提到的相同代码:
public class ApiClient {
private static Retrofit retrofit = null;
public static Retrofit getClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder()
.cacheControl(CacheControl.FORCE_NETWORK)
.addHeader("Cache-Control", "no-cache")
.addHeader("Cache-Control", "no-store");
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
OkHttpClient client = httpClient.build();
retrofit = new Retrofit.Builder()
.baseUrl(ApiInterface.SERVICE_ENDPOINT)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
return retrofit;
}
}
我的API接口
public interface ApiInterface {
String SERVICE_ENDPOINT = "https://example.com/wp-json/wp/v2/";
@GET("posts")
Call<ArrayList<CategoryResponse>> fetchlatestposts(@Query("bloglist")
int bloglist);
}
没有实时获得更新响应的问题是什么,而在暂停10-15分钟后,它将给出更新的结果。
答案 0 :(得分:0)
问题出在服务器端,WordPress已启用缓存,这是导致问题的原因。