2014-04-14 3 views
1

서버가 json 개체, 만료 및 ETAg을 보냈습니다.이 개체를 캐시에 저장하고 헤더의 ETag를 포함하여 서버에이 개체 사용 요청을 요청합니다. 응답이 304 Not Modified이면 캐시 된 리소스를 사용해야하며 200 OK이면 서버의 새 리소스를 사용해야합니다.volley - json 캐싱이 제대로 작동하지 않습니다.

(캐시가 만료되지 않은 경우) 발리는 전혀 요청을 전송하지 않거나 유효 기간이 만료되는 경우 새로운 요청하는 경우 - 없음 - 매치 + ETAG 문자열 .. 및 서버 (200)

답변

0
에 항상 응답을 전송

Volley는 캐시 항목이 아직 만료되지 않았 음을 감지하면 서버에 요청을 전혀 발행하지 않습니다.

// If it is completely expired, just send it to the network. 
if (entry.isExpired()) { 
    request.addMarker("cache-hit-expired"); 
    request.setCacheEntry(entry); 
    mNetworkQueue.put(request); 
    continue; 
} 

그리고 : : 여기를 증명할 수있는 코드 발췌은

if (!entry.refreshNeeded()) { 
    // Completely unexpired cache hit. Just deliver the response. 
    mDelivery.postResponse(request, response); 
} else { 
    // Soft-expired cache hit. We can deliver the cached response, 
    // but we need to also send the request to the network for 
    // refreshing. 
    request.addMarker("cache-hit-refresh-needed"); 
    request.setCacheEntry(entry); 

    // Mark the response as intermediate. 
    response.intermediate = true; 

    // Post the intermediate response back to the user and have 
    // the delivery then forward the request along to the network. 
    mDelivery.postResponse(request, response, new Runnable() { 
     @Override 
     public void run() { 
      try { 
       mNetworkQueue.put(request); 
      } catch (InterruptedException e) { 
       // Not much we can do about this. 
      } 
     } 
    }); 
} 

당신은 클라이언트에서 캐시를 조정할하기 위해 Cache-Control 또는 Expires 헤더에 max-age을 설정하여 서버에 자원 만료를 제어 할 수 있습니다 측면.

관련 문제