2017-01-17 3 views
0

Ion Koush Library를 사용하여 백엔드 API에서 일부 JSON을 얻으려고합니다. API 경로 중 하나에서 성공으로 처리 할 수 ​​있지만 다른 응답에서 다음 응답이 있습니다. 응답을 캐시 할 수 없습니다.Ion Koush Library - 응답이 캐시 가능하지 않습니다.

{ 
    "id_comentario": 5, 
    "id_venda_vendas": { 
     "id_venda": 139, 
     "id_cliente_cliente": { 
     "id_cliente": 22, 
     "nome": "nome", 
     "telefone": "nao_tem_ainda_layout", 
     "cpf": "cpf", 
     "endereco": "endereco", 
     "primeira_vez": true, 
     "data_nascimento": "dob", 
     "observacao": null, 
     "foto": null, 
     "email": "nao_tem_ainda_layout", 
     "id_ultima_compra": {} 
     }, 
     "id_loja_loja": { 
     "id_loja": 2, 
     "nome": "nome", 
     "nome_fantasia": "nomefantasia", 
     "cnpj": "cnpj" 
     }, 
     "data": "2016-11-18", 
     "hora": "15:36:02" 
    }, 
    "id_funcionario_funcionario": { 
     "id_funcionario": 2, 
     "nome": "nome", 
     "cargo": "cargo" 
    }, 
    "id_tipo_comentario_tipo_comentario": { 
     "id_tipo_comentario": 2, 
     "tipo": "Tipo" 
    }, 
    "descricao": "nao tem descricao" 
    } 
] 
다음 JSON 브라우저 REST 클라이언트에 의해 획득 여기

> D/LOG: (0 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: preparing request 

>D/LOG: (0 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: preparing request 

>I/LOG: (0 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Using loader: [email protected] 

>D/LOG: (0 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Executing request. 

>V/LOG: (4 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Resolving domain and connecting to all available addresses 

>V/LOG: (10 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: attempting connection to /10.0.2.2:8080 

>V/LOG: (14 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: socket connected 

>V/LOG: (14 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: 
GET /api/comentario/cliente/00013436415782/?format=json HTTP/1.1 
Host: 10.0.2.2:8080 
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; Android SDK built for x86_64 Build/LMY48X) 
Accept-Encoding: gzip, deflate 
Connection: keep-alive 
Accept: */* 
Cache-Control: no-cache 
Authorization: Token a3e8b50ae73aabad0605433f704eb628269f68c8 

>V/LOG: (16 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: request completed 

>W/EGL_emulation: eglSurfaceAttrib not implemented 
>W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fca6d3b8380, error=EGL_SUCCESS 

>D/OpenGLRenderer: endAllStagingAnimators on 0x7fca6d1e4c00 (ListView) with handle 0x7fca6406c080 

>V/LOG: (433 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Received headers: 

>  HTTP/1.0 200 OK 

>  Date: Tue, 17 Jan 2017 13:28:12 GMT 

>  Server: WSGIServer/0.1 Python/2.7.12 

>  Vary: Accept 

>  X-Frame-Options: SAMEORIGIN 

>  Content-Type: application/json 

>  Allow: GET, HEAD, OPTIONS 

>D/LOG: (433 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Response is not cacheable 
>V/LOG: (433 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Final (post cache response) headers: 

>  HTTP/1.0 200 OK 

>  Date: Tue, 17 Jan 2017 13:28:12 GMT 

>  Server: WSGIServer/0.1 Python/2.7.12 

>  Vary: Accept 

>  X-Frame-Options: SAMEORIGIN 

>  Content-Type: application/json 

>  Allow: GET, HEAD, OPTIONS 

>D/LOG: (433 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: Connection successful 

>V/LOG: (434 ms) http://10.0.2.2:8080/api/comentario/cliente/00013436415782/?format=json: closing out socket (exception) 

: 그리고 여기에 문제의 더 나은 이해를 위해 코드입니다 :

Ion.with(clientSummaryActivity.this) 
     .load("GET",url) 
     .setLogging("LOG",Log.VERBOSE) 
     .addQuery("format","json") 
     .setHeader("Authorization",getIntent().getExtras().getString("token")) 
     .asJsonArray() 
     .setCallback(new FutureCallback<JsonArray>() { 
      @Override 
      public void onCompleted(Exception e, JsonArray result) { 
       // do stuff with the result or error 
       if(e != null){ 
        Toast.makeText(clientSummaryActivity.this, "Erro na Query: " + e, Toast.LENGTH_LONG).show(); //cria balao de texto na view indicada 
        Log.v("Query Error2: ",""+e); 
        return; 
       } 
       if(result == null) 
        Log.v("Error: ","resultado vazio"); 
       else 
        Log.v("Teste: ",""+result); 
       return; 
      } 
     }); 
    } 

그리고 여기 디버그 로그입니다

요점은, 내가 REST 클라이언트에서 얻을 수있는 이유는 Ion이 응답이 캐시 가능하지 않다는 것입니다. 그리고 그것은 무엇을 의미합니까?

OBS : 다른 쿼리에서 성공적인 결과를 얻을 수 있습니다. 하지만 게시물이 너무 길어서 여기에 게시하지 않습니다.

답변

0

이온은 모든 GET 요청을 자동으로 캐시합니다. 그리고 당신의 서버는, 보시다시피, 헤더 Cache-Control: no-cache을 보냅니다,이 요청은 캐시 될 수 없다는 것을 의미합니다. 서버에서 캐시 정책을 변경하거나 .noCache()을 요청에 추가 할 수 있습니다. 내가 사용하여 해결할 수 Orest Savchak에

+0

안녕하세요, 대답 주셔서 감사합니다. 나는이 솔루션을 이미 시도했지만 성공하지는 못했다. 확인하기 위해,이 설정은 이온에서 이루어집니다. 맞죠? 또한 다음은 디버그 로그입니다. http://pastebin.com/w7JNHiYh Django RestFramework에서 헤더를 설정하는 방법을 찾고 있는데, 아마도이 방법으로 해결할 수 있습니다. –

+0

안녕하세요, 해결하지 못했습니다 .noCache()가 작동하지 않아서 사용했습니다. Ion.getDefault (getApplicationContext()). configure(). getResponseCache(). setCaching (false); 이제 모든 것이 정상입니다. 도움을 주셔서 감사합니다. –