MCPcopy Create free account
hub / github.com/apache/trafficserver / what_is_document_freshness

Method what_is_document_freshness

src/proxy/http/HttpTransact.cc:7284–7471  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////// This function takes the request and response headers for a cached object, and the current HTTP parameters, and decides if the object is still "fresh enough" to serve. One of the following values is returned: FRESHNESS_FRESH Fresh enough, serve it FRESHNESS_WARNING Stale but client says it's okay FRE

Source from the content-addressed store, hash-verified

7282//
7283//////////////////////////////////////////////////////////////////////////////
7284HttpTransact::Freshness_t
7285HttpTransact::what_is_document_freshness(State *s, HTTPHdr *client_request, HTTPHdr *cached_obj_response)
7286{
7287 bool heuristic, do_revalidate = false;
7288 int age_limit;
7289 int fresh_limit;
7290 ink_time_t current_age, response_date;
7291 uint32_t cc_mask, cooked_cc_mask;
7292 uint32_t os_specifies_revalidate;
7293
7294 if (s->cache_open_write_fail_action & CACHE_WL_FAIL_ACTION_STALE_ON_REVALIDATE) {
7295 if (is_stale_cache_response_returnable(s)) {
7296 TxnDbg(dbg_ctl_http_match, "cache_serve_stale_on_write_lock_fail, return FRESH");
7297 return (FRESHNESS_FRESH);
7298 }
7299 }
7300
7301 //////////////////////////////////////////////////////
7302 // If config file has a ttl-in-cache field set, //
7303 // it has priority over any other http headers and //
7304 // other configuration parameters. //
7305 //////////////////////////////////////////////////////
7306 if (s->cache_control.ttl_in_cache > 0) {
7307 // what matters if ttl is set is not the age of the document
7308 // but for how long it has been stored in the cache (resident time)
7309 int resident_time = s->current.now - s->response_received_time;
7310
7311 TxnDbg(dbg_ctl_http_match, "ttl-in-cache = %d, resident time = %d", s->cache_control.ttl_in_cache, resident_time);
7312 if (resident_time > s->cache_control.ttl_in_cache) {
7313 return (FRESHNESS_STALE);
7314 } else {
7315 return (FRESHNESS_FRESH);
7316 }
7317 }
7318
7319 cooked_cc_mask = cached_obj_response->get_cooked_cc_mask();
7320 os_specifies_revalidate = cooked_cc_mask & (MIME_COOKED_MASK_CC_MUST_REVALIDATE | MIME_COOKED_MASK_CC_PROXY_REVALIDATE);
7321 cc_mask = MIME_COOKED_MASK_CC_NEED_REVALIDATE_ONCE;
7322
7323 // Check to see if the server forces revalidation
7324
7325 if ((cooked_cc_mask & cc_mask) && s->cache_control.revalidate_after <= 0) {
7326 TxnDbg(dbg_ctl_http_match, "document stale due to server must-revalidate");
7327 return FRESHNESS_STALE;
7328 }
7329
7330 response_date = cached_obj_response->get_date();
7331 fresh_limit = calculate_document_freshness_limit(s, cached_obj_response, response_date, &heuristic);
7332 ink_assert(fresh_limit >= 0);
7333
7334 current_age = HttpTransactCache::calculate_document_age(s->request_sent_time, s->response_received_time, cached_obj_response,
7335 response_date, s->current.now);
7336
7337 // First check overflow status
7338 // Second if current_age is under the max, use the smaller value
7339 // Finally we take the max of current age or guaranteed max, this ensures it will
7340 // age out properly, otherwise a doc will never expire if guaranteed < document max-age
7341 if (current_age < 0) {

Callers

nothing calls this directly

Calls 8

get_cooked_cc_maskMethod · 0.80
get_dateMethod · 0.80
scheme_get_wksidxMethod · 0.80
url_getMethod · 0.80
presenceMethod · 0.80
get_cooked_cc_max_ageMethod · 0.80

Tested by

no test coverage detected