]>
Commit | Line | Data |
---|---|---|
e4e6a8db | 1 | |
2 | /* | |
62ee09ca | 3 | * $Id: refresh.cc,v 1.72 2006/05/29 00:15:02 robertc Exp $ |
e4e6a8db | 4 | * |
5 | * DEBUG: section 22 Refresh Calculation | |
6 | * AUTHOR: Harvest Derived | |
7 | * | |
2b6662ba | 8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 9 | * ---------------------------------------------------------- |
e4e6a8db | 10 | * |
2b6662ba | 11 | * Squid is the result of efforts by numerous individuals from |
12 | * the Internet community; see the CONTRIBUTORS file for full | |
13 | * details. Many organizations have provided support for Squid's | |
14 | * development; see the SPONSORS file for full details. Squid is | |
15 | * Copyrighted (C) 2001 by the Regents of the University of | |
16 | * California; see the COPYRIGHT file for full details. Squid | |
17 | * incorporates software developed and/or copyrighted by other | |
18 | * sources; see the CREDITS file for full details. | |
e4e6a8db | 19 | * |
20 | * This program is free software; you can redistribute it and/or modify | |
21 | * it under the terms of the GNU General Public License as published by | |
22 | * the Free Software Foundation; either version 2 of the License, or | |
23 | * (at your option) any later version. | |
24 | * | |
25 | * This program is distributed in the hope that it will be useful, | |
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 | * GNU General Public License for more details. | |
29 | * | |
30 | * You should have received a copy of the GNU General Public License | |
31 | * along with this program; if not, write to the Free Software | |
cbdec147 | 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 33 | * |
e4e6a8db | 34 | */ |
35 | ||
36 | #ifndef USE_POSIX_REGEX | |
37 | #define USE_POSIX_REGEX /* put before includes; always use POSIX */ | |
38 | #endif | |
39 | ||
40 | #include "squid.h" | |
62ee09ca | 41 | #include "CacheManager.h" |
e6ccf245 | 42 | #include "Store.h" |
528b2c61 | 43 | #include "MemObject.h" |
a2ac85d9 | 44 | #include "HttpRequest.h" |
924f73bc | 45 | #include "HttpReply.h" |
985c86bc | 46 | #include "SquidTime.h" |
e4e6a8db | 47 | |
7d47d8e6 | 48 | typedef enum { |
65fa5c61 | 49 | rcHTTP, |
50 | rcICP, | |
51 | #if USE_HTCP | |
52 | rcHTCP, | |
53 | #endif | |
54 | #if USE_CACHE_DIGESTS | |
55 | rcCDigest, | |
56 | #endif | |
57 | rcStore, | |
58 | rcCount | |
7d47d8e6 | 59 | } refreshCountsEnum; |
829a9357 | 60 | |
62e76326 | 61 | typedef struct |
62 | { | |
1f848b2c | 63 | bool expires; |
64 | bool min; | |
65 | bool lmfactor; | |
66 | bool max; | |
62e76326 | 67 | } |
68 | ||
69 | stale_flags; | |
65fa5c61 | 70 | |
71 | /* | |
72 | * This enumerated list assigns specific values, ala HTTP/FTP status | |
73 | * codes. All Fresh codes are in the range 100-199 and all stale | |
74 | * codes are 200-299. We might want to use these codes in logging, | |
75 | * so best to keep them consistent over time. | |
76 | */ | |
77 | enum { | |
78 | FRESH_REQUEST_MAX_STALE_ALL = 100, | |
79 | FRESH_REQUEST_MAX_STALE_VALUE, | |
80 | FRESH_EXPIRES, | |
81 | FRESH_LMFACTOR_RULE, | |
82 | FRESH_MIN_RULE, | |
83 | FRESH_OVERRIDE_EXPIRES, | |
84 | FRESH_OVERRIDE_LASTMOD, | |
85 | STALE_MUST_REVALIDATE = 200, | |
86 | STALE_RELOAD_INTO_IMS, | |
87 | STALE_FORCED_RELOAD, | |
88 | STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE, | |
89 | STALE_EXPIRES, | |
90 | STALE_MAX_RULE, | |
91 | STALE_LMFACTOR_RULE, | |
92 | STALE_DEFAULT = 299 | |
93 | }; | |
94 | ||
62e76326 | 95 | static struct RefreshCounts |
96 | { | |
829a9357 | 97 | const char *proto; |
1c3e77cd | 98 | int total; |
65fa5c61 | 99 | int status[STALE_DEFAULT + 1]; |
62e76326 | 100 | } |
101 | ||
102 | refreshCounts[rcCount]; | |
1c3e77cd | 103 | |
e4e6a8db | 104 | /* |
105 | * Defaults: | |
106 | * MIN NONE | |
107 | * PCT 20% | |
108 | * MAX 3 days | |
109 | */ | |
48f44632 | 110 | #define REFRESH_DEFAULT_MIN (time_t)0 |
c3f6d204 | 111 | #define REFRESH_DEFAULT_PCT 0.20 |
48f44632 | 112 | #define REFRESH_DEFAULT_MAX (time_t)259200 |
e4e6a8db | 113 | |
2b5133db | 114 | static const refresh_t *refreshUncompiledPattern(const char *); |
1c3e77cd | 115 | static OBJH refreshStats; |
65fa5c61 | 116 | static int refreshStaleness(const StoreEntry *, time_t, time_t, const refresh_t *, stale_flags *); |
117 | ||
118 | static refresh_t DefaultRefresh; | |
2b5133db | 119 | |
38f9c547 | 120 | const refresh_t * |
6018f0de | 121 | refreshLimits(const char *url) |
122 | { | |
123 | const refresh_t *R; | |
62e76326 | 124 | |
6018f0de | 125 | for (R = Config.Refresh; R; R = R->next) { |
62e76326 | 126 | if (!regexec(&(R->compiled_pattern), url, 0, 0, 0)) |
127 | return R; | |
6018f0de | 128 | } |
62e76326 | 129 | |
6018f0de | 130 | return NULL; |
131 | } | |
132 | ||
2b5133db | 133 | static const refresh_t * |
134 | refreshUncompiledPattern(const char *pat) | |
135 | { | |
136 | const refresh_t *R; | |
62e76326 | 137 | |
2b5133db | 138 | for (R = Config.Refresh; R; R = R->next) { |
62e76326 | 139 | if (0 == strcmp(R->pattern, pat)) |
140 | return R; | |
2b5133db | 141 | } |
62e76326 | 142 | |
2b5133db | 143 | return NULL; |
144 | } | |
145 | ||
65fa5c61 | 146 | /* |
147 | * Calculate how stale the response is (or will be at the check_time). | |
148 | * Staleness calculation is based on the following: (1) response | |
149 | * expiration time, (2) age greater than configured maximum, (3) | |
150 | * last-modified factor, and (4) age less than configured minimum. | |
151 | * | |
152 | * If the response is fresh, return -1. Otherwise return its | |
153 | * staleness. NOTE return value of 0 means the response is stale. | |
154 | * | |
155 | * The 'stale_flags' structure is used to tell the calling function | |
156 | * _why_ this response is fresh or stale. Its used, for example, | |
157 | * when the admin wants to override expiration and last-modified | |
158 | * times. | |
159 | */ | |
160 | static int | |
161 | refreshStaleness(const StoreEntry * entry, time_t check_time, time_t age, const refresh_t * R, stale_flags * sf) | |
162 | { | |
163 | /* | |
164 | * Check for an explicit expiration time. | |
165 | */ | |
62e76326 | 166 | |
65fa5c61 | 167 | if (entry->expires > -1) { |
1f848b2c | 168 | sf->expires = true; |
62e76326 | 169 | |
170 | if (entry->expires > check_time) { | |
171 | debug(22, 3) ("FRESH: expires %d >= check_time %d \n", | |
172 | (int) entry->expires, (int) check_time); | |
173 | return -1; | |
174 | } else { | |
175 | debug(22, 3) ("STALE: expires %d < check_time %d \n", | |
176 | (int) entry->expires, (int) check_time); | |
177 | return (check_time - entry->expires); | |
178 | } | |
65fa5c61 | 179 | } |
62e76326 | 180 | |
65fa5c61 | 181 | assert(age >= 0); |
182 | /* | |
183 | * Use local heuristics to determine staleness. Start with the | |
184 | * max age from the refresh_pattern rule. | |
185 | */ | |
62e76326 | 186 | |
65fa5c61 | 187 | if (age > R->max) { |
62e76326 | 188 | debug(22, 3) ("STALE: age %d > max %d \n", (int) age, (int) R->max); |
1f848b2c | 189 | sf->max = true; |
62e76326 | 190 | return (age - R->max); |
65fa5c61 | 191 | } |
62e76326 | 192 | |
65fa5c61 | 193 | /* |
194 | * Try the last-modified factor algorithm. | |
195 | */ | |
196 | if (entry->lastmod > -1 && entry->timestamp > entry->lastmod) { | |
62e76326 | 197 | /* |
198 | * stale_age is the Age of the response when it became/becomes | |
199 | * stale according to the last-modified factor algorithm. | |
200 | */ | |
201 | time_t stale_age = static_cast<time_t>((entry->timestamp - entry->lastmod) * R->pct); | |
1f848b2c | 202 | sf->lmfactor = true; |
62e76326 | 203 | |
204 | if (age >= stale_age) { | |
205 | debug(22, 3) ("STALE: age %d > stale_age %d\n", | |
206 | (int) age, (int) stale_age); | |
207 | return (age - stale_age); | |
208 | } else { | |
209 | debug(22, 3) ("FRESH: age %d <= stale_age %d\n", | |
210 | (int) age, (int) stale_age); | |
211 | return -1; | |
212 | } | |
65fa5c61 | 213 | } |
62e76326 | 214 | |
65fa5c61 | 215 | /* |
216 | * If we are here, staleness is determined by the refresh_pattern | |
217 | * configured minimum age. | |
218 | */ | |
219 | if (age <= R->min) { | |
62e76326 | 220 | debug(22, 3) ("FRESH: age %d <= min %d\n", (int) age, (int) R->min); |
1f848b2c | 221 | sf->min = true; |
62e76326 | 222 | return -1; |
65fa5c61 | 223 | } |
62e76326 | 224 | |
65fa5c61 | 225 | debug(22, 3) ("STALE: age %d > min %d\n", (int) age, (int) R->min); |
226 | return (age - R->min); | |
227 | } | |
228 | ||
829a9357 | 229 | /* return 1 if the entry must be revalidated within delta seconds |
230 | * 0 otherwise | |
231 | * | |
232 | * note: request maybe null (e.g. for cache digests build) | |
e4e6a8db | 233 | */ |
829a9357 | 234 | static int |
190154cf | 235 | refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) |
e4e6a8db | 236 | { |
6018f0de | 237 | const refresh_t *R; |
829a9357 | 238 | const char *uri = NULL; |
65fa5c61 | 239 | time_t age = 0; |
a207429f | 240 | time_t check_time = squid_curtime + delta; |
65fa5c61 | 241 | int staleness; |
242 | stale_flags sf; | |
62e76326 | 243 | |
9b5d1d21 | 244 | if (entry->mem_obj) |
62e76326 | 245 | uri = entry->mem_obj->url; |
7d47d8e6 | 246 | else if (request) |
62e76326 | 247 | uri = urlCanonical(request); |
7d47d8e6 | 248 | |
65fa5c61 | 249 | debug(22, 3) ("refreshCheck: '%s'\n", uri ? uri : "<none>"); |
250 | ||
251 | if (check_time > entry->timestamp) | |
62e76326 | 252 | age = check_time - entry->timestamp; |
253 | ||
65fa5c61 | 254 | R = uri ? refreshLimits(uri) : refreshUncompiledPattern("."); |
62e76326 | 255 | |
65fa5c61 | 256 | if (NULL == R) |
62e76326 | 257 | R = &DefaultRefresh; |
258 | ||
65fa5c61 | 259 | memset(&sf, '\0', sizeof(sf)); |
62e76326 | 260 | |
65fa5c61 | 261 | staleness = refreshStaleness(entry, check_time, age, R, &sf); |
62e76326 | 262 | |
65fa5c61 | 263 | debug(22, 3) ("Staleness = %d\n", staleness); |
264 | ||
a3d5953d | 265 | debug(22, 3) ("refreshCheck: Matched '%s %d %d%% %d'\n", |
62e76326 | 266 | R->pattern, (int) R->min, (int) (100.0 * R->pct), (int) R->max); |
267 | ||
a3d5953d | 268 | debug(22, 3) ("refreshCheck: age = %d\n", (int) age); |
62e76326 | 269 | |
49d3fcb0 | 270 | debug(22, 3) ("\tcheck_time:\t%s\n", mkrfc1123(check_time)); |
62e76326 | 271 | |
49d3fcb0 | 272 | debug(22, 3) ("\tentry->timestamp:\t%s\n", mkrfc1123(entry->timestamp)); |
65fa5c61 | 273 | |
274 | if (EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1) { | |
62e76326 | 275 | debug(22, 3) ("refreshCheck: YES: Must revalidate stale response\n"); |
276 | return STALE_MUST_REVALIDATE; | |
65fa5c61 | 277 | } |
62e76326 | 278 | |
829a9357 | 279 | /* request-specific checks */ |
280 | if (request) { | |
62e76326 | 281 | HttpHdrCc *cc = request->cache_control; |
4c3ef9b2 | 282 | |
283 | if (request->flags.ims && (R->flags.refresh_ims || Config.onoff.refresh_all_ims)) { | |
284 | /* The clients no-cache header is changed into a IMS query */ | |
285 | debug(22, 3) ("refreshCheck: YES: refresh-ims\n"); | |
286 | return STALE_FORCED_RELOAD; | |
287 | } | |
288 | ||
9f60cfdf | 289 | #if HTTP_VIOLATIONS |
62e76326 | 290 | |
291 | if (!request->flags.nocache_hack) { | |
292 | (void) 0; | |
293 | } else if (R->flags.ignore_reload) { | |
294 | /* The clients no-cache header is ignored */ | |
295 | debug(22, 3) ("refreshCheck: MAYBE: ignore-reload\n"); | |
296 | } else if (R->flags.reload_into_ims || Config.onoff.reload_into_ims) { | |
297 | /* The clients no-cache header is changed into a IMS query */ | |
298 | debug(22, 3) ("refreshCheck: YES: reload-into-ims\n"); | |
299 | return STALE_RELOAD_INTO_IMS; | |
300 | } else { | |
301 | /* The clients no-cache header is not overridden on this request */ | |
302 | debug(22, 3) ("refreshCheck: YES: client reload\n"); | |
303 | request->flags.nocache = 1; | |
304 | return STALE_FORCED_RELOAD; | |
305 | } | |
306 | ||
9f60cfdf | 307 | #endif |
62e76326 | 308 | if (NULL != cc) { |
309 | if (cc->max_age > -1) { | |
085008f9 | 310 | #if HTTP_VIOLATIONS |
62e76326 | 311 | if (R->flags.ignore_reload && cc->max_age == 0) {} else |
528b2c61 | 312 | #endif |
62e76326 | 313 | { |
528b2c61 | 314 | #if 0 |
62e76326 | 315 | |
316 | if (cc->max_age == 0) { | |
317 | debug (22,3) ("refreshCheck: YES: client-max-age = 0\n"); | |
318 | return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE; | |
319 | } | |
320 | ||
085008f9 | 321 | #endif |
62e76326 | 322 | if (age > cc->max_age) { |
323 | debug(22, 3) ("refreshCheck: YES: age > client-max-age\n"); | |
324 | return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE; | |
325 | } | |
326 | } | |
327 | } | |
328 | ||
329 | if (EBIT_TEST(cc->mask, CC_MAX_STALE) && staleness > -1) { | |
330 | if (cc->max_stale < 0) { | |
331 | /* max-stale directive without a value */ | |
332 | debug(22, 3) ("refreshCheck: NO: max-stale wildcard\n"); | |
333 | return FRESH_REQUEST_MAX_STALE_ALL; | |
334 | } else if (staleness < cc->max_stale) { | |
335 | debug(22, 3) ("refreshCheck: NO: staleness < max-stale\n"); | |
336 | return FRESH_REQUEST_MAX_STALE_VALUE; | |
337 | } | |
338 | } | |
339 | } | |
48f44632 | 340 | } |
62e76326 | 341 | |
65fa5c61 | 342 | if (-1 == staleness) { |
62e76326 | 343 | if (sf.expires) |
344 | return FRESH_EXPIRES; | |
345 | ||
346 | assert(!sf.max); | |
347 | ||
348 | if (sf.lmfactor) | |
349 | return FRESH_LMFACTOR_RULE; | |
350 | ||
351 | assert(sf.min); | |
352 | ||
353 | return FRESH_MIN_RULE; | |
1dfa1d81 | 354 | } |
62e76326 | 355 | |
65fa5c61 | 356 | /* |
357 | * At this point the response is stale, unless one of | |
542c4d60 | 358 | * the override options kicks in. |
65fa5c61 | 359 | */ |
360 | if (sf.expires) { | |
361 | #if HTTP_VIOLATIONS | |
62e76326 | 362 | |
363 | if (R->flags.override_expire && age < R->min) { | |
364 | debug(22, 3) ("refreshCheck: NO: age < min && override-expire\n"); | |
365 | return FRESH_OVERRIDE_EXPIRES; | |
366 | } | |
367 | ||
65fa5c61 | 368 | #endif |
62e76326 | 369 | return STALE_EXPIRES; |
e4e6a8db | 370 | } |
62e76326 | 371 | |
65fa5c61 | 372 | if (sf.max) |
62e76326 | 373 | return STALE_MAX_RULE; |
374 | ||
65fa5c61 | 375 | if (sf.lmfactor) { |
9f60cfdf | 376 | #if HTTP_VIOLATIONS |
62e76326 | 377 | |
378 | if (R->flags.override_lastmod && age < R->min) { | |
379 | debug(22, 3) ("refreshCheck: NO: age < min && override-lastmod\n"); | |
380 | return FRESH_OVERRIDE_LASTMOD; | |
381 | } | |
382 | ||
65fa5c61 | 383 | #endif |
62e76326 | 384 | return STALE_LMFACTOR_RULE; |
e4e6a8db | 385 | } |
62e76326 | 386 | |
65fa5c61 | 387 | return STALE_DEFAULT; |
e4e6a8db | 388 | } |
48f44632 | 389 | |
cfa9f1cb | 390 | int |
391 | refreshIsCachable(const StoreEntry * entry) | |
392 | { | |
393 | /* | |
394 | * Don't look at the request to avoid no-cache and other nuisances. | |
395 | * the object should have a mem_obj so the URL will be found there. | |
6a2f3fcf | 396 | * minimum_expiry_time seconds delta (defaults to 60 seconds), to |
397 | * avoid objects which expire almost immediately, and which can't | |
398 | * be refreshed. | |
cfa9f1cb | 399 | */ |
6a2f3fcf | 400 | int reason = refreshCheck(entry, NULL, Config.minimum_expiry_time); |
65fa5c61 | 401 | refreshCounts[rcStore].total++; |
402 | refreshCounts[rcStore].status[reason]++; | |
62e76326 | 403 | |
451c8350 | 404 | if (reason < STALE_MUST_REVALIDATE) |
62e76326 | 405 | /* Does not need refresh. This is certainly cachable */ |
406 | return 1; | |
407 | ||
cfa9f1cb | 408 | if (entry->lastmod < 0) |
62e76326 | 409 | /* Last modified is needed to do a refresh */ |
410 | return 0; | |
411 | ||
cfa9f1cb | 412 | if (entry->mem_obj == NULL) |
62e76326 | 413 | /* no mem_obj? */ |
414 | return 1; | |
415 | ||
528b2c61 | 416 | if (entry->getReply() == NULL) |
62e76326 | 417 | /* no reply? */ |
418 | return 1; | |
419 | ||
528b2c61 | 420 | if (entry->getReply()->content_length == 0) |
62e76326 | 421 | /* No use refreshing (caching?) 0 byte objects */ |
422 | return 0; | |
423 | ||
cfa9f1cb | 424 | /* This seems to be refreshable. Cache it */ |
425 | return 1; | |
426 | } | |
427 | ||
829a9357 | 428 | /* refreshCheck... functions below are protocol-specific wrappers around |
429 | * refreshCheck() function above */ | |
430 | ||
431 | int | |
190154cf | 432 | refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request) |
7d47d8e6 | 433 | { |
65fa5c61 | 434 | int reason = refreshCheck(entry, request, 0); |
435 | refreshCounts[rcHTTP].total++; | |
436 | refreshCounts[rcHTTP].status[reason]++; | |
437 | return (reason < 200) ? 0 : 1; | |
829a9357 | 438 | } |
439 | ||
440 | int | |
190154cf | 441 | refreshCheckICP(const StoreEntry * entry, HttpRequest * request) |
7d47d8e6 | 442 | { |
65fa5c61 | 443 | int reason = refreshCheck(entry, request, 30); |
444 | refreshCounts[rcICP].total++; | |
445 | refreshCounts[rcICP].status[reason]++; | |
446 | return (reason < 200) ? 0 : 1; | |
829a9357 | 447 | } |
448 | ||
65fa5c61 | 449 | #if USE_HTCP |
32b3cf93 | 450 | int |
190154cf | 451 | refreshCheckHTCP(const StoreEntry * entry, HttpRequest * request) |
32b3cf93 | 452 | { |
65fa5c61 | 453 | int reason = refreshCheck(entry, request, 10); |
454 | refreshCounts[rcHTCP].total++; | |
455 | refreshCounts[rcHTCP].status[reason]++; | |
456 | return (reason < 200) ? 0 : 1; | |
32b3cf93 | 457 | } |
62e76326 | 458 | |
65fa5c61 | 459 | #endif |
32b3cf93 | 460 | |
65fa5c61 | 461 | #if USE_CACHE_DIGESTS |
829a9357 | 462 | int |
7d47d8e6 | 463 | refreshCheckDigest(const StoreEntry * entry, time_t delta) |
464 | { | |
65fa5c61 | 465 | int reason = refreshCheck(entry, |
62e76326 | 466 | entry->mem_obj ? entry->mem_obj->request : NULL, |
467 | delta); | |
65fa5c61 | 468 | refreshCounts[rcCDigest].total++; |
469 | refreshCounts[rcCDigest].status[reason]++; | |
470 | return (reason < 200) ? 0 : 1; | |
6018f0de | 471 | } |
62e76326 | 472 | |
65fa5c61 | 473 | #endif |
6018f0de | 474 | |
48f44632 | 475 | time_t |
476 | getMaxAge(const char *url) | |
477 | { | |
6018f0de | 478 | const refresh_t *R; |
a3d5953d | 479 | debug(22, 3) ("getMaxAge: '%s'\n", url); |
62e76326 | 480 | |
6018f0de | 481 | if ((R = refreshLimits(url))) |
62e76326 | 482 | return R->max; |
6018f0de | 483 | else |
62e76326 | 484 | return REFRESH_DEFAULT_MAX; |
48f44632 | 485 | } |
1c3e77cd | 486 | |
829a9357 | 487 | static void |
62e76326 | 488 | |
829a9357 | 489 | refreshCountsStats(StoreEntry * sentry, struct RefreshCounts *rc) |
490 | { | |
cc7cfa8e | 491 | int sum = 0; |
492 | int tot = rc->total; | |
493 | ||
829a9357 | 494 | storeAppendPrintf(sentry, "\n\n%s histogram:\n", rc->proto); |
65fa5c61 | 495 | storeAppendPrintf(sentry, "Count\t%%Total\tCategory\n"); |
829a9357 | 496 | |
65fa5c61 | 497 | #define refreshCountsStatsEntry(code,desc) { \ |
498 | storeAppendPrintf(sentry, "%6d\t%6.2f\t%s\n", \ | |
499 | rc->status[code], xpercent(rc->status[code], tot), desc); \ | |
500 | sum += rc->status[code]; \ | |
cc7cfa8e | 501 | } |
65fa5c61 | 502 | |
503 | refreshCountsStatsEntry(FRESH_REQUEST_MAX_STALE_ALL, | |
62e76326 | 504 | "Fresh: request max-stale wildcard"); |
65fa5c61 | 505 | refreshCountsStatsEntry(FRESH_REQUEST_MAX_STALE_VALUE, |
62e76326 | 506 | "Fresh: request max-stale value"); |
65fa5c61 | 507 | refreshCountsStatsEntry(FRESH_EXPIRES, |
62e76326 | 508 | "Fresh: expires time not reached"); |
65fa5c61 | 509 | refreshCountsStatsEntry(FRESH_LMFACTOR_RULE, |
62e76326 | 510 | "Fresh: refresh_pattern last-mod factor percentage"); |
65fa5c61 | 511 | refreshCountsStatsEntry(FRESH_MIN_RULE, |
62e76326 | 512 | "Fresh: refresh_pattern min value"); |
65fa5c61 | 513 | refreshCountsStatsEntry(FRESH_OVERRIDE_EXPIRES, |
62e76326 | 514 | "Fresh: refresh_pattern override expires"); |
65fa5c61 | 515 | refreshCountsStatsEntry(FRESH_OVERRIDE_LASTMOD, |
62e76326 | 516 | "Fresh: refresh_pattern override lastmod"); |
65fa5c61 | 517 | refreshCountsStatsEntry(STALE_MUST_REVALIDATE, |
62e76326 | 518 | "Stale: response has must-revalidate"); |
65fa5c61 | 519 | refreshCountsStatsEntry(STALE_RELOAD_INTO_IMS, |
62e76326 | 520 | "Stale: changed reload into IMS"); |
65fa5c61 | 521 | refreshCountsStatsEntry(STALE_FORCED_RELOAD, |
62e76326 | 522 | "Stale: request has no-cache directive"); |
65fa5c61 | 523 | refreshCountsStatsEntry(STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE, |
62e76326 | 524 | "Stale: age exceeds request max-age value"); |
65fa5c61 | 525 | refreshCountsStatsEntry(STALE_EXPIRES, |
62e76326 | 526 | "Stale: expires time reached"); |
65fa5c61 | 527 | refreshCountsStatsEntry(STALE_MAX_RULE, |
62e76326 | 528 | "Stale: refresh_pattern max age rule"); |
65fa5c61 | 529 | refreshCountsStatsEntry(STALE_LMFACTOR_RULE, |
62e76326 | 530 | "Stale: refresh_pattern last-mod factor percentage"); |
65fa5c61 | 531 | refreshCountsStatsEntry(STALE_DEFAULT, |
62e76326 | 532 | "Stale: by default"); |
65fa5c61 | 533 | |
7d47d8e6 | 534 | tot = sum; /* paranoid: "total" line shows 100% if we forgot nothing */ |
65fa5c61 | 535 | storeAppendPrintf(sentry, "%6d\t%6.2f\tTOTAL\n", |
62e76326 | 536 | rc->total, xpercent(rc->total, tot)); |
65fa5c61 | 537 | \ |
62e76326 | 538 | storeAppendPrintf(sentry, "\n"); |
829a9357 | 539 | } |
540 | ||
1c3e77cd | 541 | static void |
542 | refreshStats(StoreEntry * sentry) | |
543 | { | |
829a9357 | 544 | int i; |
545 | int total = 0; | |
546 | ||
547 | /* get total usage count */ | |
62e76326 | 548 | |
829a9357 | 549 | for (i = 0; i < rcCount; ++i) |
62e76326 | 550 | total += refreshCounts[i].total; |
829a9357 | 551 | |
552 | /* protocol usage histogram */ | |
553 | storeAppendPrintf(sentry, "\nRefreshCheck calls per protocol\n\n"); | |
62e76326 | 554 | |
829a9357 | 555 | storeAppendPrintf(sentry, "Protocol\t#Calls\t%%Calls\n"); |
62e76326 | 556 | |
829a9357 | 557 | for (i = 0; i < rcCount; ++i) |
62e76326 | 558 | storeAppendPrintf(sentry, "%10s\t%6d\t%6.2f\n", |
559 | refreshCounts[i].proto, | |
560 | refreshCounts[i].total, | |
561 | xpercent(refreshCounts[i].total, total)); | |
829a9357 | 562 | |
563 | /* per protocol histograms */ | |
564 | storeAppendPrintf(sentry, "\n\nRefreshCheck histograms for various protocols\n"); | |
62e76326 | 565 | |
829a9357 | 566 | for (i = 0; i < rcCount; ++i) |
62e76326 | 567 | refreshCountsStats(sentry, &refreshCounts[i]); |
1c3e77cd | 568 | } |
569 | ||
570 | void | |
9bc73deb | 571 | refreshInit(void) |
1c3e77cd | 572 | { |
829a9357 | 573 | memset(refreshCounts, 0, sizeof(refreshCounts)); |
574 | refreshCounts[rcHTTP].proto = "HTTP"; | |
575 | refreshCounts[rcICP].proto = "ICP"; | |
65fa5c61 | 576 | #if USE_HTCP |
62e76326 | 577 | |
32b3cf93 | 578 | refreshCounts[rcHTCP].proto = "HTCP"; |
65fa5c61 | 579 | #endif |
62e76326 | 580 | |
cfa9f1cb | 581 | refreshCounts[rcStore].proto = "On Store"; |
65fa5c61 | 582 | #if USE_CACHE_DIGESTS |
62e76326 | 583 | |
829a9357 | 584 | refreshCounts[rcCDigest].proto = "Cache Digests"; |
65fa5c61 | 585 | #endif |
62e76326 | 586 | |
65fa5c61 | 587 | memset(&DefaultRefresh, '\0', sizeof(DefaultRefresh)); |
588 | DefaultRefresh.pattern = "<none>"; | |
589 | DefaultRefresh.min = REFRESH_DEFAULT_MIN; | |
590 | DefaultRefresh.pct = REFRESH_DEFAULT_PCT; | |
591 | DefaultRefresh.max = REFRESH_DEFAULT_MAX; | |
1c3e77cd | 592 | } |
62ee09ca | 593 | |
594 | void | |
595 | refreshRegisterWithCacheManager(CacheManager & manager) | |
596 | { | |
597 | manager.registerAction("refresh", | |
598 | "Refresh Algorithm Statistics", | |
599 | refreshStats, | |
600 | 0, | |
601 | 1); | |
602 | } |