Given a set of alternates, select the best match. The current school of thought: quality 1st, freshness 2nd. Loop through alternates and find the one with the highest quality factor. Then determine if it is fresh enough. If not, find the next best match. In keeping with "quality is job 1", subsequent matches will only be considered if their quality is equal to the quality of the first
| 175 | |
| 176 | */ |
| 177 | int |
| 178 | HttpTransactCache::SelectFromAlternates(CacheHTTPInfoVector *cache_vector, HTTPHdr *client_request, |
| 179 | const HttpConfigAccessor *http_config_params) |
| 180 | { |
| 181 | time_t current_age, best_age = CacheHighAgeWatermark; |
| 182 | time_t t_now = 0; |
| 183 | int best_index = -1; |
| 184 | float best_Q = -1.0; |
| 185 | float unacceptable_Q = 0.0; |
| 186 | |
| 187 | int alt_count = cache_vector->count(); |
| 188 | if (alt_count == 0) { |
| 189 | return -1; |
| 190 | } |
| 191 | |
| 192 | Dbg(dbg_ctl_http_match, "[SelectFromAlternates] # alternates = %d", alt_count); |
| 193 | Dbg(dbg_ctl_http_seq, "[SelectFromAlternates] %d alternates for this cached doc", alt_count); |
| 194 | if (dbg_ctl_http_alts.on()) { |
| 195 | fprintf(stderr, "[alts] There are %d alternates for this request header.\n", alt_count); |
| 196 | } |
| 197 | |
| 198 | // so that plugins can make cache reads for http |
| 199 | // docs to check if the doc exists in the cache |
| 200 | if (!client_request->valid()) { |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | for (int i = 0; i < alt_count; i++) { |
| 205 | float Q; |
| 206 | CacheHTTPInfo *obj = cache_vector->get(i); |
| 207 | HTTPHdr *cached_request = obj->request_get(); |
| 208 | HTTPHdr *cached_response = obj->response_get(); |
| 209 | |
| 210 | if (!(obj->object_key_get().is_zero())) { |
| 211 | ink_assert(cached_request->valid()); |
| 212 | ink_assert(cached_response->valid()); |
| 213 | |
| 214 | Q = calculate_quality_of_match(http_config_params, client_request, cached_request, cached_response); |
| 215 | |
| 216 | if (alt_count > 1) { |
| 217 | if (t_now == 0) { |
| 218 | t_now = ink_hrtime_to_sec(ink_get_hrtime()); |
| 219 | } |
| 220 | current_age = HttpTransactCache::calculate_document_age(obj->request_sent_time_get(), obj->response_received_time_get(), |
| 221 | cached_response, cached_response->get_date(), t_now); |
| 222 | // Overflow? |
| 223 | if (current_age < 0) { |
| 224 | current_age = CacheHighAgeWatermark; |
| 225 | } |
| 226 | } else { |
| 227 | current_age = static_cast<time_t>(0); |
| 228 | } |
| 229 | |
| 230 | if (dbg_ctl_http_alts.on()) { |
| 231 | fprintf(stderr, "[alts] ---- alternate #%d (Q = %g) has these request/response hdrs:\n", i + 1, Q); |
| 232 | char b[4096]; |
| 233 | int used, tmp, offset; |
| 234 | int done; |
nothing calls this directly
no test coverage detected