2 * Copyright (C) 1996-2020 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"
41 * Flags indicating which staleness algorithm has been applied.
44 bool expires
; ///< Expires: header absolute timestamp limit
45 bool min
; ///< Heuristic minimum age limited
46 bool lmfactor
; ///< Last-Modified with heuristic determines limit
47 bool max
; ///< Configured maximum age limit
51 * This enumerated list assigns specific values, ala HTTP/FTP status
52 * codes. All Fresh codes are in the range 100-199 and all stale
53 * codes are 200-299. We might want to use these codes in logging,
54 * so best to keep them consistent over time.
57 FRESH_REQUEST_MAX_STALE_ALL
= 100,
58 FRESH_REQUEST_MAX_STALE_VALUE
,
62 FRESH_OVERRIDE_EXPIRES
,
63 FRESH_OVERRIDE_LASTMOD
,
64 STALE_MUST_REVALIDATE
= 200,
65 STALE_RELOAD_INTO_IMS
,
67 STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
,
75 static struct RefreshCounts
{
78 int status
[STALE_DEFAULT
+ 1];
79 } refreshCounts
[rcCount
];
81 static const RefreshPattern
*refreshUncompiledPattern(const char *);
82 static OBJH refreshStats
;
83 static int refreshStaleness(const StoreEntry
* entry
, time_t check_time
, const time_t age
, const RefreshPattern
* R
, stale_flags
* sf
);
85 static RefreshPattern
DefaultRefresh("<none>", 0);
87 /** Locate the first refresh_pattern rule that matches the given URL by regex.
89 * \return A pointer to the refresh_pattern parameters to use, or nullptr if there is no match.
91 const RefreshPattern
*
92 refreshLimits(const char *url
)
94 for (auto R
= Config
.Refresh
; R
; R
= R
->next
) {
95 ++(R
->stats
.matchTests
);
96 if (R
->pattern
.match(url
)) {
97 ++(R
->stats
.matchCount
);
105 /** Locate the first refresh_pattern rule that has the given uncompiled regex.
107 * \note There is only one reference to this function, below. It always passes "." as the pattern.
108 * This function is only ever called if there is no URI. Because a regex match is impossible, Squid
109 * forces the "." rule to apply (if it exists)
111 * \return A pointer to the refresh_pattern parameters to use, or nullptr if there is no match.
113 static const RefreshPattern
*
114 refreshUncompiledPattern(const char *pat
)
116 for (auto R
= Config
.Refresh
; R
; R
= R
->next
) {
117 if (0 == strcmp(R
->pattern
.c_str(), pat
))
125 * Calculate how stale the response is (or will be at the check_time).
127 * We try the following ways until one gives a result:
129 * 1. response expiration time, if one was set
130 * 2. age greater than configured maximum
131 * 3. last-modified factor algorithm
132 * 4. age less than configured minimum
135 * \param entry the StoreEntry being examined
136 * \param check_time the time (maybe future) at which we want to know whether $
137 * \param age the age of the entry at check_time
138 * \param R the refresh_pattern rule that matched this entry
139 * \param sf small struct to indicate reason for stale/fresh decision
141 * \retval -1 If the response is fresh.
142 * \retval >0 The amount of staleness.
143 * \retval 0 NOTE return value of 0 means the response is stale.
146 refreshStaleness(const StoreEntry
* entry
, time_t check_time
, const time_t age
, const RefreshPattern
* R
, stale_flags
* sf
)
148 // 1. If the cached object has an explicit expiration time, then we rely on this and
149 // completely ignore the Min, Percent and Max values in the refresh_pattern.
150 if (entry
->expires
> -1) {
153 if (entry
->expires
> check_time
) {
154 debugs(22, 3, "FRESH: expires " << entry
->expires
<<
155 " >= check_time " << check_time
<< " ");
159 debugs(22, 3, "STALE: expires " << entry
->expires
<<
160 " < check_time " << check_time
<< " ");
162 return (check_time
- entry
->expires
);
166 debugs(22, 3, "No explicit expiry given, using heuristics to determine freshness");
168 // 2. If the entry is older than the maximum age in the refresh_pattern, it is STALE.
170 debugs(22, 3, "STALE: age " << age
<< " > max " << R
->max
<< " ");
172 return (age
- R
->max
);
175 // 3. If there is a Last-Modified header, try the last-modified factor algorithm.
176 const time_t lastmod_delta
= entry
->timestamp
- entry
->lastModified();
177 if (lastmod_delta
> 0) {
178 /* stale_age is the age of the response when it became/becomes stale according to
179 * the last-modified factor algorithm. It's how long we can consider the response
180 * fresh from the time we cached it.
182 time_t stale_age
= static_cast<time_t>(lastmod_delta
* R
->pct
);
184 debugs(22,3, "Last modified " << lastmod_delta
<< " sec before we cached it, L-M factor " <<
185 (100.0 * R
->pct
) << "% = " << stale_age
<< " sec freshness lifetime");
188 if (age
>= stale_age
) {
189 debugs(22, 3, "STALE: age " << age
<< " > stale_age " << stale_age
);
190 return (age
- stale_age
);
192 debugs(22, 3, "FRESH: age " << age
<< " <= stale_age " << stale_age
);
197 // 4. If the entry is not as old as the minimum age in the refresh_pattern, it is FRESH.
199 debugs(22, 3, "FRESH: age (" << age
<< " sec) is less than configured minimum (" << R
->min
<< " sec)");
204 // 5. default is stale, by the amount we missed the minimum by
205 debugs(22, 3, "STALE: No explicit expiry, no last modified, and older than configured minimum.");
206 return (age
- R
->min
);
209 /** Checks whether a store entry is fresh or stale, and why.
211 * This is where all aspects of request, response and squid configuration
212 * meet to decide whether a response is cacheable or not:
214 * 1. Client request headers that affect cacheability, e.g.
215 * - Cache-Control: no-cache
216 * - Cache-Control: max-age=N
217 * - Cache-Control: max-stale[=N]
220 * 2. Server response headers that affect cacheability, e.g.
222 * - Cache-Control: proxy-revalidate
223 * - Cache-Control: must-revalidate
224 * - Cache-Control: no-cache
225 * - Cache-Control: max-age=N
226 * - Cache-Control: s-maxage=N
231 * 3. Configuration options, e.g.
232 * - reload-into-ims (refresh_pattern)
233 * - ignore-reload (refresh_pattern)
234 * - refresh-ims (refresh_pattern)
235 * - override-lastmod (refresh_pattern)
236 * - override-expire (refresh_pattern)
237 * - reload_into_ims (global option)
238 * - refresh_all_ims (global option)
240 * \returns a status code (from enum above):
241 * - FRESH_REQUEST_MAX_STALE_ALL
242 * - FRESH_REQUEST_MAX_STALE_VALUE
244 * - FRESH_LMFACTOR_RULE
246 * - FRESH_OVERRIDE_EXPIRES
247 * - FRESH_OVERRIDE_LASTMOD
248 * - STALE_MUST_REVALIDATE
249 * - STALE_RELOAD_INTO_IMS
250 * - STALE_FORCED_RELOAD
251 * - STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
254 * - STALE_LMFACTOR_RULE
258 * \note request may be NULL (e.g. for cache digests build)
260 * \note the store entry being examined is not necessarily cached (e.g. if
261 * this response is being evaluated for the first time)
264 refreshCheck(const StoreEntry
* entry
, HttpRequest
* request
, time_t delta
)
267 time_t check_time
= squid_curtime
+ delta
;
271 // get the URL of this entry, if there is one
272 static const SBuf
nilUri("<none>");
275 uri
= entry
->mem_obj
->storeId();
277 uri
= request
->effectiveRequestUri();
279 debugs(22, 3, "checking freshness of URI: " << uri
);
281 // age is not necessarily the age now, but the age at the given check_time
282 if (check_time
> entry
->timestamp
)
283 age
= check_time
- entry
->timestamp
;
285 // FIXME: what to do when age < 0 or counter overflow?
288 /* We need a refresh rule. In order of preference:
290 * 1. the rule that matches this URI by regex
291 * 2. the "." rule from the config file
292 * 3. the default "." rule
294 // XXX: performance regression. c_str() reallocates
295 const RefreshPattern
*R
= (uri
!= nilUri
) ? refreshLimits(uri
.c_str()) : refreshUncompiledPattern(".");
299 debugs(22, 3, "Matched '" << R
->pattern
.c_str() << " " <<
300 (int) R
->min
<< " " << (int) (100.0 * R
->pct
) << "%% " <<
301 (int) R
->max
<< "'");
303 debugs(22, 3, "\tage:\t" << age
);
305 debugs(22, 3, "\tcheck_time:\t" << mkrfc1123(check_time
));
307 debugs(22, 3, "\tentry->timestamp:\t" << mkrfc1123(entry
->timestamp
));
309 if (request
&& !request
->flags
.ignoreCc
) {
310 const HttpHdrCc
*const cc
= request
->cache_control
;
312 if (cc
&& cc
->hasMinFresh(&minFresh
)) {
313 debugs(22, 3, "\tage + min-fresh:\t" << age
<< " + " <<
314 minFresh
<< " = " << age
+ minFresh
);
315 debugs(22, 3, "\tcheck_time + min-fresh:\t" << check_time
<< " + "
316 << minFresh
<< " = " <<
317 mkrfc1123(check_time
+ minFresh
));
319 check_time
+= minFresh
;
323 memset(&sf
, '\0', sizeof(sf
));
325 staleness
= refreshStaleness(entry
, check_time
, age
, R
, &sf
);
327 debugs(22, 3, "Staleness = " << staleness
);
329 const auto reply
= entry
->hasFreshestReply(); // may be nil
331 // stale-if-error requires any failure be passed thru when its period is over.
332 int staleIfError
= -1;
333 if (request
&& reply
&& reply
->cache_control
&&
334 reply
->cache_control
->hasStaleIfError(&staleIfError
) &&
335 staleIfError
< staleness
) {
337 debugs(22, 3, "stale-if-error period expired. Will produce error if validation fails.");
338 request
->flags
.failOnValidationError
= true;
341 /* If the origin server specified either of:
342 * Cache-Control: must-revalidate
343 * Cache-Control: proxy-revalidate
344 * the spec says the response must always be revalidated if stale.
346 const bool revalidateAlways
= EBIT_TEST(entry
->flags
, ENTRY_REVALIDATE_ALWAYS
);
347 if (revalidateAlways
|| (staleness
> -1 &&
348 EBIT_TEST(entry
->flags
, ENTRY_REVALIDATE_STALE
))) {
349 debugs(22, 3, "YES: Must revalidate stale object (origin set " <<
350 (revalidateAlways
? "no-cache or private" :
351 "must-revalidate, proxy-revalidate or s-maxage") << ")");
353 request
->flags
.failOnValidationError
= true;
354 return STALE_MUST_REVALIDATE
;
357 /* request-specific checks */
358 if (request
&& !request
->flags
.ignoreCc
) {
359 HttpHdrCc
*cc
= request
->cache_control
;
361 /* If the request is an IMS request, and squid is configured NOT to service this from cache
362 * (either by 'refresh-ims' in the refresh pattern or 'refresh_all_ims on' globally)
363 * then force a reload from the origin.
365 if (request
->flags
.ims
&& (R
->flags
.refresh_ims
|| Config
.onoff
.refresh_all_ims
)) {
366 // The client's no-cache header is changed into a IMS query
367 debugs(22, 3, "YES: Client IMS request forcing revalidation of object (refresh-ims option)");
368 return STALE_FORCED_RELOAD
;
371 #if USE_HTTP_VIOLATIONS
372 /* Normally a client reload request ("Cache-Control: no-cache" or "Pragma: no-cache")
373 * means we must treat this response as STALE and fetch a new one.
375 * However, some options exist to override this behaviour. For example, we might just
376 * revalidate our existing response, or even just serve it up without revalidating it.
378 * ---- Note on the meaning of nocache_hack -----
380 * The nocache_hack flag has a very specific and complex meaning:
382 * (a) this is a reload request ("Cache-Control: no-cache" or "Pragma: no-cache" header)
383 * and (b) the configuration file either has at least one refresh_pattern with
384 * ignore-reload or reload-into-ims (not necessarily the rule matching this request) or
385 * the global reload_into_ims is set to on
387 * In other words: this is a client reload, and we might need to override
388 * the default behaviour (but we might not).
390 * "nocache_hack" is a pretty deceptive name for such a complicated meaning.
392 if (request
->flags
.noCacheHack()) {
394 if (R
->flags
.ignore_reload
) {
395 /* The client's no-cache header is ignored completely - we'll try to serve
396 * what we have (assuming it's still fresh, etc.)
398 debugs(22, 3, "MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
399 } else if (R
->flags
.reload_into_ims
|| Config
.onoff
.reload_into_ims
) {
400 /* The client's no-cache header is not honoured completely - we'll just try
401 * to revalidate our cached copy (IMS to origin) instead of fetching a new
402 * copy with an unconditional GET.
404 debugs(22, 3, "YES: Client reload request - cheating, only revalidating with origin (reload-into-ims option)");
405 return STALE_RELOAD_INTO_IMS
;
407 /* The client's no-cache header is honoured - we fetch a new copy from origin */
408 debugs(22, 3, "YES: Client reload request - fetching new copy from origin");
409 request
->flags
.noCache
= true;
410 return STALE_FORCED_RELOAD
;
415 // Check the Cache-Control client request header
420 if (cc
->hasMaxAge(&maxAge
)) {
422 // RFC 8246: reply contains CC:immutable then ignore client CC:max-age=N
423 if (reply
&& reply
->cache_control
&& reply
->cache_control
->hasImmutable()) {
424 debugs(22, 3, "MAYBE: Ignoring client CC:max-age=" << maxAge
<< " request - 'Cache-Control: immutable'");
426 #if USE_HTTP_VIOLATIONS
427 // Ignore of client "Cache-Control: max-age=0" header
428 } else if (R
->flags
.ignore_reload
&& maxAge
== 0) {
429 debugs(22, 3, "MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
432 // Honour client "Cache-Control: max-age=x" header
433 } else if (age
> maxAge
|| maxAge
== 0) {
434 debugs(22, 3, "YES: Revalidating object - client 'Cache-Control: max-age=" << maxAge
<< "'");
435 return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
;
439 // max-stale directive
441 if (cc
->hasMaxStale(&maxStale
) && staleness
> -1) {
442 if (maxStale
==HttpHdrCc::MAX_STALE_ANY
) {
443 debugs(22, 3, "NO: Client accepts a stale response of any age - 'Cache-Control: max-stale'");
444 return FRESH_REQUEST_MAX_STALE_ALL
;
445 } else if (staleness
< maxStale
) {
446 debugs(22, 3, "NO: Client accepts a stale response - 'Cache-Control: max-stale=" << maxStale
<< "'");
447 return FRESH_REQUEST_MAX_STALE_VALUE
;
453 // If the object is fresh, return the right FRESH_ code
454 if (-1 == staleness
) {
455 debugs(22, 3, "Object isn't stale..");
457 debugs(22, 3, "returning FRESH_EXPIRES");
458 return FRESH_EXPIRES
;
464 debugs(22, 3, "returning FRESH_LMFACTOR_RULE");
465 return FRESH_LMFACTOR_RULE
;
470 debugs(22, 3, "returning FRESH_MIN_RULE");
471 return FRESH_MIN_RULE
;
475 * At this point the response is stale, unless one of
476 * the override options kicks in.
477 * NOTE: max-stale config blocks the overrides.
479 int max_stale
= (R
->max_stale
>= 0 ? R
->max_stale
: Config
.maxStale
);
480 if ( max_stale
>= 0 && staleness
> max_stale
) {
481 debugs(22, 3, "YES: refresh_pattern max-stale=N limit from squid.conf");
483 request
->flags
.failOnValidationError
= true;
484 return STALE_MAX_STALE
;
488 #if USE_HTTP_VIOLATIONS
490 if (R
->flags
.override_expire
&& age
< R
->min
) {
491 debugs(22, 3, "NO: Serving from cache - even though explicit expiry has passed, we enforce Min value (override-expire option)");
492 return FRESH_OVERRIDE_EXPIRES
;
496 return STALE_EXPIRES
;
500 return STALE_MAX_RULE
;
503 #if USE_HTTP_VIOLATIONS
504 if (R
->flags
.override_lastmod
&& age
< R
->min
) {
505 debugs(22, 3, "NO: Serving from cache - even though L-M factor says the object is stale, we enforce Min value (override-lastmod option)");
506 return FRESH_OVERRIDE_LASTMOD
;
509 debugs(22, 3, "YES: L-M factor says the object is stale'");
510 return STALE_LMFACTOR_RULE
;
513 debugs(22, 3, "returning STALE_DEFAULT");
514 return STALE_DEFAULT
;
518 * This is called by http.cc once it has received and parsed the origin server's
519 * response headers. It uses the result as part of its algorithm to decide whether a
520 * response should be cached.
522 * \retval true if the entry is cacheable, regardless of whether FRESH or STALE
523 * \retval false if the entry is not cacheable
525 * TODO: this algorithm seems a bit odd and might not be quite right. Verify against HTTPbis.
528 refreshIsCachable(const StoreEntry
* entry
)
531 * Don't look at the request to avoid no-cache and other nuisances.
532 * the object should have a mem_obj so the URL will be found there.
533 * minimum_expiry_time seconds delta (defaults to 60 seconds), to
534 * avoid objects which expire almost immediately, and which can't
537 int reason
= refreshCheck(entry
, NULL
, Config
.minimum_expiry_time
);
538 ++ refreshCounts
[rcStore
].total
;
539 ++ refreshCounts
[rcStore
].status
[reason
];
541 if (reason
< STALE_MUST_REVALIDATE
)
542 /* Does not need refresh. This is certainly cachable */
545 if (entry
->lastModified() < 0)
546 /* We should know entry's modification time to do a refresh */
549 if (entry
->mem_obj
== NULL
)
553 if (entry
->mem_obj
->baseReply().content_length
== 0)
554 /* No use refreshing (caching?) 0 byte objects */
557 /* This seems to be refreshable. Cache it */
561 /// whether reply is stale if it is a hit
563 refreshIsStaleIfHit(const int reason
)
567 case FRESH_LMFACTOR_RULE
:
576 * Protocol-specific wrapper around refreshCheck() function.
578 * Note the reason for STALE/FRESH then return true/false respectively.
584 refreshCheckHTTP(const StoreEntry
* entry
, HttpRequest
* request
)
586 int reason
= refreshCheck(entry
, request
, 0);
587 ++ refreshCounts
[rcHTTP
].total
;
588 ++ refreshCounts
[rcHTTP
].status
[reason
];
589 request
->flags
.staleIfHit
= refreshIsStaleIfHit(reason
);
590 // TODO: Treat collapsed responses as fresh but second-hand.
591 return (Config
.onoff
.offline
|| reason
< 200) ? 0 : 1;
594 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
596 refreshCheckICP(const StoreEntry
* entry
, HttpRequest
* request
)
598 int reason
= refreshCheck(entry
, request
, 30);
599 ++ refreshCounts
[rcICP
].total
;
600 ++ refreshCounts
[rcICP
].status
[reason
];
601 return (reason
< 200) ? 0 : 1;
605 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
607 refreshCheckHTCP(const StoreEntry
* entry
, HttpRequest
* request
)
609 int reason
= refreshCheck(entry
, request
, 10);
610 ++ refreshCounts
[rcHTCP
].total
;
611 ++ refreshCounts
[rcHTCP
].status
[reason
];
612 return (reason
< 200) ? 0 : 1;
617 #if USE_CACHE_DIGESTS
618 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
620 refreshCheckDigest(const StoreEntry
* entry
, time_t delta
)
622 int reason
= refreshCheck(entry
,
623 entry
->mem_obj
? entry
->mem_obj
->request
.getRaw() : nullptr,
625 ++ refreshCounts
[rcCDigest
].total
;
626 ++ refreshCounts
[rcCDigest
].status
[reason
];
627 return (reason
< 200) ? 0 : 1;
632 * Get the configured maximum caching time for objects with this URL
633 * according to refresh_pattern.
635 * Used by http.cc when generating a upstream requests to ensure that
636 * responses it is given are fresh enough to be worth caching.
638 * \retval pattern-max if there is a refresh_pattern matching the URL configured.
639 * \retval REFRESH_DEFAULT_MAX if there are no explicit limits configured
642 getMaxAge(const char *url
)
644 const RefreshPattern
*R
;
645 debugs(22, 3, "getMaxAge: '" << url
<< "'");
647 if ((R
= refreshLimits(url
)))
650 return REFRESH_DEFAULT_MAX
;
654 refreshCountsStatsEntry(StoreEntry
* sentry
, struct RefreshCounts
&rc
, int code
, const char *desc
)
656 storeAppendPrintf(sentry
, "%6d\t%6.2f\t%s\n", rc
.status
[code
], xpercent(rc
.status
[code
], rc
.total
), desc
);
657 return rc
.status
[code
];
661 refreshCountsStats(StoreEntry
* sentry
, struct RefreshCounts
&rc
)
666 storeAppendPrintf(sentry
, "\n\n%s histogram:\n", rc
.proto
);
667 storeAppendPrintf(sentry
, "Count\t%%Total\tCategory\n");
670 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_REQUEST_MAX_STALE_ALL
, "Fresh: request max-stale wildcard");
671 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_REQUEST_MAX_STALE_VALUE
, "Fresh: request max-stale value");
672 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_EXPIRES
, "Fresh: expires time not reached");
673 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_LMFACTOR_RULE
, "Fresh: refresh_pattern last-mod factor percentage");
674 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_MIN_RULE
, "Fresh: refresh_pattern min value");
675 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_OVERRIDE_EXPIRES
, "Fresh: refresh_pattern override-expires");
676 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_OVERRIDE_LASTMOD
, "Fresh: refresh_pattern override-lastmod");
677 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_MUST_REVALIDATE
, "Stale: response has must-revalidate");
678 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_RELOAD_INTO_IMS
, "Stale: changed reload into IMS");
679 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_FORCED_RELOAD
, "Stale: request has no-cache directive");
680 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
, "Stale: age exceeds request max-age value");
681 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_EXPIRES
, "Stale: expires time reached");
682 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_MAX_RULE
, "Stale: refresh_pattern max age rule");
683 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_LMFACTOR_RULE
, "Stale: refresh_pattern last-mod factor percentage");
684 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_DEFAULT
, "Stale: by default");
685 storeAppendPrintf(sentry
, "\n");
689 refreshStats(StoreEntry
* sentry
)
691 // display per-rule counts of usage and tests
692 storeAppendPrintf(sentry
, "\nRefresh pattern usage:\n\n");
693 storeAppendPrintf(sentry
, " Used \tChecks \t%% Matches\tPattern\n");
694 for (const RefreshPattern
*R
= Config
.Refresh
; R
; R
= R
->next
) {
695 storeAppendPrintf(sentry
, " %10" PRIu64
"\t%10" PRIu64
"\t%6.2f\t%s%s\n",
698 xpercent(R
->stats
.matchCount
, R
->stats
.matchTests
),
699 (R
->pattern
.flags
®_ICASE
? "-i " : ""),
706 /* get total usage count */
708 for (i
= 0; i
< rcCount
; ++i
)
709 total
+= refreshCounts
[i
].total
;
711 /* protocol usage histogram */
712 storeAppendPrintf(sentry
, "\nRefreshCheck calls per protocol\n\n");
714 storeAppendPrintf(sentry
, "Protocol\t#Calls\t%%Calls\n");
716 for (i
= 0; i
< rcCount
; ++i
)
717 storeAppendPrintf(sentry
, "%10s\t%6d\t%6.2f\n",
718 refreshCounts
[i
].proto
,
719 refreshCounts
[i
].total
,
720 xpercent(refreshCounts
[i
].total
, total
));
722 /* per protocol histograms */
723 storeAppendPrintf(sentry
, "\n\nRefreshCheck histograms for various protocols\n");
725 for (i
= 0; i
< rcCount
; ++i
)
726 refreshCountsStats(sentry
, refreshCounts
[i
]);
730 refreshRegisterWithCacheManager(void)
732 Mgr::RegisterAction("refresh", "Refresh Algorithm Statistics", refreshStats
, 0, 1);
738 memset(refreshCounts
, 0, sizeof(refreshCounts
));
739 refreshCounts
[rcHTTP
].proto
= "HTTP";
740 refreshCounts
[rcICP
].proto
= "ICP";
743 refreshCounts
[rcHTCP
].proto
= "HTCP";
746 refreshCounts
[rcStore
].proto
= "On Store";
747 #if USE_CACHE_DIGESTS
749 refreshCounts
[rcCDigest
].proto
= "Cache Digests";
752 refreshRegisterWithCacheManager();