2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 22 Refresh Calculation */
11 #ifndef USE_POSIX_REGEX
12 #define USE_POSIX_REGEX /* put before includes; always use POSIX */
16 #include "HttpHdrCc.h"
17 #include "HttpReply.h"
18 #include "HttpRequest.h"
19 #include "MemObject.h"
20 #include "mgr/Registration.h"
21 #include "RefreshPattern.h"
22 #include "SquidConfig.h"
23 #include "SquidTime.h"
42 * Flags indicating which staleness algorithm has been applied.
45 bool expires
; ///< Expires: header absolute timestamp limit
46 bool min
; ///< Heuristic minimum age limited
47 bool lmfactor
; ///< Last-Modified with heuristic determines limit
48 bool max
; ///< Configured maximum age limit
52 * This enumerated list assigns specific values, ala HTTP/FTP status
53 * codes. All Fresh codes are in the range 100-199 and all stale
54 * codes are 200-299. We might want to use these codes in logging,
55 * so best to keep them consistent over time.
58 FRESH_REQUEST_MAX_STALE_ALL
= 100,
59 FRESH_REQUEST_MAX_STALE_VALUE
,
63 FRESH_OVERRIDE_EXPIRES
,
64 FRESH_OVERRIDE_LASTMOD
,
65 STALE_MUST_REVALIDATE
= 200,
66 STALE_RELOAD_INTO_IMS
,
68 STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
,
76 static struct RefreshCounts
{
79 int status
[STALE_DEFAULT
+ 1];
80 } refreshCounts
[rcCount
];
88 #define REFRESH_DEFAULT_MIN (time_t)0
89 #define REFRESH_DEFAULT_PCT 0.20
90 #define REFRESH_DEFAULT_MAX (time_t)259200
92 static const RefreshPattern
*refreshUncompiledPattern(const char *);
93 static OBJH refreshStats
;
94 static int refreshStaleness(const StoreEntry
* entry
, time_t check_time
, const time_t age
, const RefreshPattern
* R
, stale_flags
* sf
);
96 static RefreshPattern DefaultRefresh
;
98 /** Locate the first refresh_pattern rule that matches the given URL by regex.
100 * \note regexec() returns 0 if matched, and REG_NOMATCH otherwise
102 * \return A pointer to the refresh_pattern parameters to use, or NULL if there is no match.
104 const RefreshPattern
*
105 refreshLimits(const char *url
)
107 const RefreshPattern
*R
;
109 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
110 ++(R
->stats
.matchTests
);
111 if (!regexec(&(R
->compiled_pattern
), url
, 0, 0, 0)) {
112 ++(R
->stats
.matchCount
);
120 /** Locate the first refresh_pattern rule that has the given uncompiled regex.
122 * \note There is only one reference to this function, below. It always passes "." as the pattern.
123 * This function is only ever called if there is no URI. Because a regex match is impossible, Squid
124 * forces the "." rule to apply (if it exists)
126 * \return A pointer to the refresh_pattern parameters to use, or NULL if there is no match.
128 static const RefreshPattern
*
129 refreshUncompiledPattern(const char *pat
)
131 const RefreshPattern
*R
;
133 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
134 if (0 == strcmp(R
->pattern
, pat
))
142 * Calculate how stale the response is (or will be at the check_time).
144 * We try the following ways until one gives a result:
146 * 1. response expiration time, if one was set
147 * 2. age greater than configured maximum
148 * 3. last-modified factor algorithm
149 * 4. age less than configured minimum
152 * \param entry the StoreEntry being examined
153 * \param check_time the time (maybe future) at which we want to know whether $
154 * \param age the age of the entry at check_time
155 * \param R the refresh_pattern rule that matched this entry
156 * \param sf small struct to indicate reason for stale/fresh decision
158 * \retval -1 If the response is fresh.
159 * \retval >0 The amount of staleness.
160 * \retval 0 NOTE return value of 0 means the response is stale.
163 refreshStaleness(const StoreEntry
* entry
, time_t check_time
, const time_t age
, const RefreshPattern
* R
, stale_flags
* sf
)
165 // 1. If the cached object has an explicit expiration time, then we rely on this and
166 // completely ignore the Min, Percent and Max values in the refresh_pattern.
167 if (entry
->expires
> -1) {
170 if (entry
->expires
> check_time
) {
171 debugs(22, 3, "FRESH: expires " << entry
->expires
<<
172 " >= check_time " << check_time
<< " ");
176 debugs(22, 3, "STALE: expires " << entry
->expires
<<
177 " < check_time " << check_time
<< " ");
179 return (check_time
- entry
->expires
);
183 debugs(22, 3, "No explicit expiry given, using heuristics to determine freshness");
185 // 2. If the entry is older than the maximum age in the refresh_pattern, it is STALE.
187 debugs(22, 3, "STALE: age " << age
<< " > max " << R
->max
<< " ");
189 return (age
- R
->max
);
192 // 3. If there is a Last-Modified header, try the last-modified factor algorithm.
193 if (entry
->lastmod
> -1 && entry
->timestamp
> entry
->lastmod
) {
195 /* lastmod_delta is the difference between the last-modified date of the response
196 * and the time we cached it. It's how "old" the response was when we got it.
198 time_t lastmod_delta
= entry
->timestamp
- entry
->lastmod
;
200 /* stale_age is the age of the response when it became/becomes stale according to
201 * the last-modified factor algorithm. It's how long we can consider the response
202 * fresh from the time we cached it.
204 time_t stale_age
= static_cast<time_t>(lastmod_delta
* R
->pct
);
206 debugs(22,3, "Last modified " << lastmod_delta
<< " sec before we cached it, L-M factor " <<
207 (100.0 * R
->pct
) << "% = " << stale_age
<< " sec freshness lifetime");
210 if (age
>= stale_age
) {
211 debugs(22, 3, "STALE: age " << age
<< " > stale_age " << stale_age
);
212 return (age
- stale_age
);
214 debugs(22, 3, "FRESH: age " << age
<< " <= stale_age " << stale_age
);
219 // 4. If the entry is not as old as the minimum age in the refresh_pattern, it is FRESH.
221 debugs(22, 3, "FRESH: age (" << age
<< " sec) is less than configured minimum (" << R
->min
<< " sec)");
226 // 5. default is stale, by the amount we missed the minimum by
227 debugs(22, 3, "STALE: No explicit expiry, no last modified, and older than configured minimum.");
228 return (age
- R
->min
);
231 /** Checks whether a store entry is fresh or stale, and why.
233 * This is where all aspects of request, response and squid configuration
234 * meet to decide whether a response is cacheable or not:
236 * 1. Client request headers that affect cacheability, e.g.
237 * - Cache-Control: no-cache
238 * - Cache-Control: max-age=N
239 * - Cache-Control: max-stale[=N]
242 * 2. Server response headers that affect cacheability, e.g.
244 * - Cache-Control: proxy-revalidate
245 * - Cache-Control: must-revalidate
246 * - Cache-Control: no-cache
247 * - Cache-Control: max-age=N
248 * - Cache-Control: s-maxage=N
253 * 3. Configuration options, e.g.
254 * - reload-into-ims (refresh_pattern)
255 * - ignore-reload (refresh_pattern)
256 * - refresh-ims (refresh_pattern)
257 * - override-lastmod (refresh_pattern)
258 * - override-expire (refresh_pattern)
259 * - reload_into_ims (global option)
260 * - refresh_all_ims (global option)
262 * \returns a status code (from enum above):
263 * - FRESH_REQUEST_MAX_STALE_ALL
264 * - FRESH_REQUEST_MAX_STALE_VALUE
266 * - FRESH_LMFACTOR_RULE
268 * - FRESH_OVERRIDE_EXPIRES
269 * - FRESH_OVERRIDE_LASTMOD
270 * - STALE_MUST_REVALIDATE
271 * - STALE_RELOAD_INTO_IMS
272 * - STALE_FORCED_RELOAD
273 * - STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
276 * - STALE_LMFACTOR_RULE
280 * \note request may be NULL (e.g. for cache digests build)
282 * \note the store entry being examined is not necessarily cached (e.g. if
283 * this response is being evaluated for the first time)
286 refreshCheck(const StoreEntry
* entry
, HttpRequest
* request
, time_t delta
)
288 const char *uri
= NULL
;
290 time_t check_time
= squid_curtime
+ delta
;
294 // get the URL of this entry, if there is one
296 uri
= entry
->mem_obj
->storeId();
298 uri
= urlCanonical(request
);
300 debugs(22, 3, "checking freshness of '" << (uri
? uri
: "<none>") << "'");
302 // age is not necessarily the age now, but the age at the given check_time
303 if (check_time
> entry
->timestamp
)
304 age
= check_time
- entry
->timestamp
;
306 // FIXME: what to do when age < 0 or counter overflow?
309 /* We need a refresh rule. In order of preference:
311 * 1. the rule that matches this URI by regex
312 * 2. the "." rule from the config file
313 * 3. the default "." rule
315 const RefreshPattern
*R
= uri
? refreshLimits(uri
) : refreshUncompiledPattern(".");
319 debugs(22, 3, "Matched '" << R
->pattern
<< " " <<
320 (int) R
->min
<< " " << (int) (100.0 * R
->pct
) << "%% " <<
321 (int) R
->max
<< "'");
323 debugs(22, 3, "\tage:\t" << age
);
325 debugs(22, 3, "\tcheck_time:\t" << mkrfc1123(check_time
));
327 debugs(22, 3, "\tentry->timestamp:\t" << mkrfc1123(entry
->timestamp
));
329 if (request
&& !request
->flags
.ignoreCc
) {
330 const HttpHdrCc
*const cc
= request
->cache_control
;
331 if (cc
&& cc
->hasMinFresh()) {
332 const int32_t minFresh
=cc
->minFresh();
333 debugs(22, 3, "\tage + min-fresh:\t" << age
<< " + " <<
334 minFresh
<< " = " << age
+ minFresh
);
335 debugs(22, 3, "\tcheck_time + min-fresh:\t" << check_time
<< " + "
336 << minFresh
<< " = " <<
337 mkrfc1123(check_time
+ minFresh
));
339 check_time
+= minFresh
;
343 memset(&sf
, '\0', sizeof(sf
));
345 staleness
= refreshStaleness(entry
, check_time
, age
, R
, &sf
);
347 debugs(22, 3, "Staleness = " << staleness
);
349 // stale-if-error requires any failure be passed thru when its period is over.
350 if (request
&& entry
->mem_obj
&& entry
->mem_obj
->getReply() && entry
->mem_obj
->getReply()->cache_control
&&
351 entry
->mem_obj
->getReply()->cache_control
->hasStaleIfError() &&
352 entry
->mem_obj
->getReply()->cache_control
->staleIfError() < staleness
) {
354 debugs(22, 3, "stale-if-error period expired. Will produce error if validation fails.");
355 request
->flags
.failOnValidationError
= true;
358 /* If the origin server specified either of:
359 * Cache-Control: must-revalidate
360 * Cache-Control: proxy-revalidate
361 * the spec says the response must always be revalidated if stale.
363 if (EBIT_TEST(entry
->flags
, ENTRY_REVALIDATE
) && staleness
> -1
364 #if USE_HTTP_VIOLATIONS
365 && !R
->flags
.ignore_must_revalidate
368 debugs(22, 3, "YES: Must revalidate stale object (origin set must-revalidate or proxy-revalidate)");
370 request
->flags
.failOnValidationError
= true;
371 return STALE_MUST_REVALIDATE
;
374 /* request-specific checks */
375 if (request
&& !request
->flags
.ignoreCc
) {
376 HttpHdrCc
*cc
= request
->cache_control
;
378 /* If the request is an IMS request, and squid is configured NOT to service this from cache
379 * (either by 'refresh-ims' in the refresh pattern or 'refresh_all_ims on' globally)
380 * then force a reload from the origin.
382 if (request
->flags
.ims
&& (R
->flags
.refresh_ims
|| Config
.onoff
.refresh_all_ims
)) {
383 // The client's no-cache header is changed into a IMS query
384 debugs(22, 3, "YES: Client IMS request forcing revalidation of object (refresh-ims option)");
385 return STALE_FORCED_RELOAD
;
388 #if USE_HTTP_VIOLATIONS
389 /* Normally a client reload request ("Cache-Control: no-cache" or "Pragma: no-cache")
390 * means we must treat this reponse as STALE and fetch a new one.
392 * However, some options exist to override this behaviour. For example, we might just
393 * revalidate our existing response, or even just serve it up without revalidating it.
395 * ---- Note on the meaning of nocache_hack -----
397 * The nocache_hack flag has a very specific and complex meaning:
399 * (a) this is a reload request ("Cache-Control: no-cache" or "Pragma: no-cache" header)
400 * and (b) the configuration file either has at least one refresh_pattern with
401 * ignore-reload or reload-into-ims (not necessarily the rule matching this request) or
402 * the global reload_into_ims is set to on
404 * In other words: this is a client reload, and we might need to override
405 * the default behaviour (but we might not).
407 * "nocache_hack" is a pretty deceptive name for such a complicated meaning.
409 if (request
->flags
.noCacheHack()) {
411 if (R
->flags
.ignore_reload
) {
412 /* The client's no-cache header is ignored completely - we'll try to serve
413 * what we have (assuming it's still fresh, etc.)
415 debugs(22, 3, "MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
416 } else if (R
->flags
.reload_into_ims
|| Config
.onoff
.reload_into_ims
) {
417 /* The client's no-cache header is not honoured completely - we'll just try
418 * to revalidate our cached copy (IMS to origin) instead of fetching a new
419 * copy with an unconditional GET.
421 debugs(22, 3, "YES: Client reload request - cheating, only revalidating with origin (reload-into-ims option)");
422 return STALE_RELOAD_INTO_IMS
;
424 /* The client's no-cache header is honoured - we fetch a new copy from origin */
425 debugs(22, 3, "YES: Client reload request - fetching new copy from origin");
426 request
->flags
.noCache
= true;
427 return STALE_FORCED_RELOAD
;
432 // Check the Cache-Control client request header
436 if (cc
->hasMaxAge()) {
437 #if USE_HTTP_VIOLATIONS
438 // Ignore client "Cache-Control: max-age=0" header
439 if (R
->flags
.ignore_reload
&& cc
->maxAge() == 0) {
440 debugs(22, 3, "MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
444 // Honour client "Cache-Control: max-age=x" header
445 if (age
> cc
->maxAge() || cc
->maxAge() == 0) {
446 debugs(22, 3, "YES: Revalidating object - client 'Cache-Control: max-age=" << cc
->maxAge() << "'");
447 return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
;
452 // max-stale directive
453 if (cc
->hasMaxStale() && staleness
> -1) {
454 if (cc
->maxStale()==HttpHdrCc::MAX_STALE_ANY
) {
455 debugs(22, 3, "NO: Client accepts a stale response of any age - 'Cache-Control: max-stale'");
456 return FRESH_REQUEST_MAX_STALE_ALL
;
457 } else if (staleness
< cc
->maxStale()) {
458 debugs(22, 3, "NO: Client accepts a stale response - 'Cache-Control: max-stale=" << cc
->maxStale() << "'");
459 return FRESH_REQUEST_MAX_STALE_VALUE
;
465 // If the object is fresh, return the right FRESH_ code
466 if (-1 == staleness
) {
467 debugs(22, 3, "Object isn't stale..");
469 debugs(22, 3, "returning FRESH_EXPIRES");
470 return FRESH_EXPIRES
;
476 debugs(22, 3, "returning FRESH_LMFACTOR_RULE");
477 return FRESH_LMFACTOR_RULE
;
482 debugs(22, 3, "returning FRESH_MIN_RULE");
483 return FRESH_MIN_RULE
;
487 * At this point the response is stale, unless one of
488 * the override options kicks in.
489 * NOTE: max-stale config blocks the overrides.
491 int max_stale
= (R
->max_stale
>= 0 ? R
->max_stale
: Config
.maxStale
);
492 if ( max_stale
>= 0 && staleness
> max_stale
) {
493 debugs(22, 3, "YES: refresh_pattern max-stale=N limit from squid.conf");
495 request
->flags
.failOnValidationError
= true;
496 return STALE_MAX_STALE
;
500 #if USE_HTTP_VIOLATIONS
502 if (R
->flags
.override_expire
&& age
< R
->min
) {
503 debugs(22, 3, "NO: Serving from cache - even though explicit expiry has passed, we enforce Min value (override-expire option)");
504 return FRESH_OVERRIDE_EXPIRES
;
508 return STALE_EXPIRES
;
512 return STALE_MAX_RULE
;
515 #if USE_HTTP_VIOLATIONS
516 if (R
->flags
.override_lastmod
&& age
< R
->min
) {
517 debugs(22, 3, "NO: Serving from cache - even though L-M factor says the object is stale, we enforce Min value (override-lastmod option)");
518 return FRESH_OVERRIDE_LASTMOD
;
521 debugs(22, 3, "YES: L-M factor says the object is stale'");
522 return STALE_LMFACTOR_RULE
;
525 debugs(22, 3, "returning STALE_DEFAULT");
526 return STALE_DEFAULT
;
530 * This is called by http.cc once it has received and parsed the origin server's
531 * response headers. It uses the result as part of its algorithm to decide whether a
532 * response should be cached.
534 * \retval true if the entry is cacheable, regardless of whether FRESH or STALE
535 * \retval false if the entry is not cacheable
537 * TODO: this algorithm seems a bit odd and might not be quite right. Verify against HTTPbis.
540 refreshIsCachable(const StoreEntry
* entry
)
543 * Don't look at the request to avoid no-cache and other nuisances.
544 * the object should have a mem_obj so the URL will be found there.
545 * minimum_expiry_time seconds delta (defaults to 60 seconds), to
546 * avoid objects which expire almost immediately, and which can't
549 int reason
= refreshCheck(entry
, NULL
, Config
.minimum_expiry_time
);
550 ++ refreshCounts
[rcStore
].total
;
551 ++ refreshCounts
[rcStore
].status
[reason
];
553 if (reason
< STALE_MUST_REVALIDATE
)
554 /* Does not need refresh. This is certainly cachable */
557 if (entry
->lastmod
< 0)
558 /* Last modified is needed to do a refresh */
561 if (entry
->mem_obj
== NULL
)
565 if (entry
->getReply() == NULL
)
569 if (entry
->getReply()->content_length
== 0)
570 /* No use refreshing (caching?) 0 byte objects */
573 /* This seems to be refreshable. Cache it */
577 /// whether reply is stale if it is a hit
579 refreshIsStaleIfHit(const int reason
)
583 case FRESH_LMFACTOR_RULE
:
592 * Protocol-specific wrapper around refreshCheck() function.
594 * Note the reason for STALE/FRESH then return true/false respectively.
600 refreshCheckHTTP(const StoreEntry
* entry
, HttpRequest
* request
)
602 int reason
= refreshCheck(entry
, request
, 0);
603 ++ refreshCounts
[rcHTTP
].total
;
604 ++ refreshCounts
[rcHTTP
].status
[reason
];
605 request
->flags
.staleIfHit
= refreshIsStaleIfHit(reason
);
606 return (Config
.onoff
.offline
|| reason
< 200) ? 0 : 1;
609 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
611 refreshCheckICP(const StoreEntry
* entry
, HttpRequest
* request
)
613 int reason
= refreshCheck(entry
, request
, 30);
614 ++ refreshCounts
[rcICP
].total
;
615 ++ refreshCounts
[rcICP
].status
[reason
];
616 return (reason
< 200) ? 0 : 1;
620 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
622 refreshCheckHTCP(const StoreEntry
* entry
, HttpRequest
* request
)
624 int reason
= refreshCheck(entry
, request
, 10);
625 ++ refreshCounts
[rcHTCP
].total
;
626 ++ refreshCounts
[rcHTCP
].status
[reason
];
627 return (reason
< 200) ? 0 : 1;
632 #if USE_CACHE_DIGESTS
633 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
635 refreshCheckDigest(const StoreEntry
* entry
, time_t delta
)
637 int reason
= refreshCheck(entry
,
638 entry
->mem_obj
? entry
->mem_obj
->request
: NULL
,
640 ++ refreshCounts
[rcCDigest
].total
;
641 ++ refreshCounts
[rcCDigest
].status
[reason
];
642 return (reason
< 200) ? 0 : 1;
647 * Get the configured maximum caching time for objects with this URL
648 * according to refresh_pattern.
650 * Used by http.cc when generating a upstream requests to ensure that
651 * responses it is given are fresh enough to be worth caching.
653 * \retval pattern-max if there is a refresh_pattern matching the URL configured.
654 * \retval REFRESH_DEFAULT_MAX if there are no explicit limits configured
657 getMaxAge(const char *url
)
659 const RefreshPattern
*R
;
660 debugs(22, 3, "getMaxAge: '" << url
<< "'");
662 if ((R
= refreshLimits(url
)))
665 return REFRESH_DEFAULT_MAX
;
669 refreshCountsStatsEntry(StoreEntry
* sentry
, struct RefreshCounts
&rc
, int code
, const char *desc
)
671 storeAppendPrintf(sentry
, "%6d\t%6.2f\t%s\n", rc
.status
[code
], xpercent(rc
.status
[code
], rc
.total
), desc
);
672 return rc
.status
[code
];
676 refreshCountsStats(StoreEntry
* sentry
, struct RefreshCounts
&rc
)
681 storeAppendPrintf(sentry
, "\n\n%s histogram:\n", rc
.proto
);
682 storeAppendPrintf(sentry
, "Count\t%%Total\tCategory\n");
685 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_REQUEST_MAX_STALE_ALL
, "Fresh: request max-stale wildcard");
686 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_REQUEST_MAX_STALE_VALUE
, "Fresh: request max-stale value");
687 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_EXPIRES
, "Fresh: expires time not reached");
688 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_LMFACTOR_RULE
, "Fresh: refresh_pattern last-mod factor percentage");
689 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_MIN_RULE
, "Fresh: refresh_pattern min value");
690 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_OVERRIDE_EXPIRES
, "Fresh: refresh_pattern override-expires");
691 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_OVERRIDE_LASTMOD
, "Fresh: refresh_pattern override-lastmod");
692 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_MUST_REVALIDATE
, "Stale: response has must-revalidate");
693 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_RELOAD_INTO_IMS
, "Stale: changed reload into IMS");
694 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_FORCED_RELOAD
, "Stale: request has no-cache directive");
695 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
, "Stale: age exceeds request max-age value");
696 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_EXPIRES
, "Stale: expires time reached");
697 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_MAX_RULE
, "Stale: refresh_pattern max age rule");
698 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_LMFACTOR_RULE
, "Stale: refresh_pattern last-mod factor percentage");
699 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_DEFAULT
, "Stale: by default");
700 storeAppendPrintf(sentry
, "\n");
704 refreshStats(StoreEntry
* sentry
)
706 // display per-rule counts of usage and tests
707 storeAppendPrintf(sentry
, "\nRefresh pattern usage:\n\n");
708 storeAppendPrintf(sentry
, " Used \tChecks \t%% Matches\tPattern\n");
709 for (const RefreshPattern
*R
= Config
.Refresh
; R
; R
= R
->next
) {
710 storeAppendPrintf(sentry
, " %10" PRIu64
"\t%10" PRIu64
"\t%6.2f\t%s%s\n",
713 xpercent(R
->stats
.matchCount
, R
->stats
.matchTests
),
714 (R
->flags
.icase
? "-i " : ""),
721 /* get total usage count */
723 for (i
= 0; i
< rcCount
; ++i
)
724 total
+= refreshCounts
[i
].total
;
726 /* protocol usage histogram */
727 storeAppendPrintf(sentry
, "\nRefreshCheck calls per protocol\n\n");
729 storeAppendPrintf(sentry
, "Protocol\t#Calls\t%%Calls\n");
731 for (i
= 0; i
< rcCount
; ++i
)
732 storeAppendPrintf(sentry
, "%10s\t%6d\t%6.2f\n",
733 refreshCounts
[i
].proto
,
734 refreshCounts
[i
].total
,
735 xpercent(refreshCounts
[i
].total
, total
));
737 /* per protocol histograms */
738 storeAppendPrintf(sentry
, "\n\nRefreshCheck histograms for various protocols\n");
740 for (i
= 0; i
< rcCount
; ++i
)
741 refreshCountsStats(sentry
, refreshCounts
[i
]);
745 refreshRegisterWithCacheManager(void)
747 Mgr::RegisterAction("refresh", "Refresh Algorithm Statistics", refreshStats
, 0, 1);
753 memset(refreshCounts
, 0, sizeof(refreshCounts
));
754 refreshCounts
[rcHTTP
].proto
= "HTTP";
755 refreshCounts
[rcICP
].proto
= "ICP";
758 refreshCounts
[rcHTCP
].proto
= "HTCP";
761 refreshCounts
[rcStore
].proto
= "On Store";
762 #if USE_CACHE_DIGESTS
764 refreshCounts
[rcCDigest
].proto
= "Cache Digests";
767 memset(&DefaultRefresh
, '\0', sizeof(DefaultRefresh
));
768 DefaultRefresh
.pattern
= "<none>";
769 DefaultRefresh
.min
= REFRESH_DEFAULT_MIN
;
770 DefaultRefresh
.pct
= REFRESH_DEFAULT_PCT
;
771 DefaultRefresh
.max
= REFRESH_DEFAULT_MAX
;
773 refreshRegisterWithCacheManager();