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 debugs(22, 3, "YES: Must revalidate stale object (origin set must-revalidate, proxy-revalidate, no-cache, s-maxage, or private)");
366 request
->flags
.failOnValidationError
= true;
367 return STALE_MUST_REVALIDATE
;
370 /* request-specific checks */
371 if (request
&& !request
->flags
.ignoreCc
) {
372 HttpHdrCc
*cc
= request
->cache_control
;
374 /* If the request is an IMS request, and squid is configured NOT to service this from cache
375 * (either by 'refresh-ims' in the refresh pattern or 'refresh_all_ims on' globally)
376 * then force a reload from the origin.
378 if (request
->flags
.ims
&& (R
->flags
.refresh_ims
|| Config
.onoff
.refresh_all_ims
)) {
379 // The client's no-cache header is changed into a IMS query
380 debugs(22, 3, "YES: Client IMS request forcing revalidation of object (refresh-ims option)");
381 return STALE_FORCED_RELOAD
;
384 #if USE_HTTP_VIOLATIONS
385 /* Normally a client reload request ("Cache-Control: no-cache" or "Pragma: no-cache")
386 * means we must treat this reponse as STALE and fetch a new one.
388 * However, some options exist to override this behaviour. For example, we might just
389 * revalidate our existing response, or even just serve it up without revalidating it.
391 * ---- Note on the meaning of nocache_hack -----
393 * The nocache_hack flag has a very specific and complex meaning:
395 * (a) this is a reload request ("Cache-Control: no-cache" or "Pragma: no-cache" header)
396 * and (b) the configuration file either has at least one refresh_pattern with
397 * ignore-reload or reload-into-ims (not necessarily the rule matching this request) or
398 * the global reload_into_ims is set to on
400 * In other words: this is a client reload, and we might need to override
401 * the default behaviour (but we might not).
403 * "nocache_hack" is a pretty deceptive name for such a complicated meaning.
405 if (request
->flags
.noCacheHack()) {
407 if (R
->flags
.ignore_reload
) {
408 /* The client's no-cache header is ignored completely - we'll try to serve
409 * what we have (assuming it's still fresh, etc.)
411 debugs(22, 3, "MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
412 } else if (R
->flags
.reload_into_ims
|| Config
.onoff
.reload_into_ims
) {
413 /* The client's no-cache header is not honoured completely - we'll just try
414 * to revalidate our cached copy (IMS to origin) instead of fetching a new
415 * copy with an unconditional GET.
417 debugs(22, 3, "YES: Client reload request - cheating, only revalidating with origin (reload-into-ims option)");
418 return STALE_RELOAD_INTO_IMS
;
420 /* The client's no-cache header is honoured - we fetch a new copy from origin */
421 debugs(22, 3, "YES: Client reload request - fetching new copy from origin");
422 request
->flags
.noCache
= true;
423 return STALE_FORCED_RELOAD
;
428 // Check the Cache-Control client request header
432 if (cc
->hasMaxAge()) {
433 #if USE_HTTP_VIOLATIONS
434 // Ignore client "Cache-Control: max-age=0" header
435 if (R
->flags
.ignore_reload
&& cc
->maxAge() == 0) {
436 debugs(22, 3, "MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
440 // Honour client "Cache-Control: max-age=x" header
441 if (age
> cc
->maxAge() || cc
->maxAge() == 0) {
442 debugs(22, 3, "YES: Revalidating object - client 'Cache-Control: max-age=" << cc
->maxAge() << "'");
443 return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
;
448 // max-stale directive
449 if (cc
->hasMaxStale() && staleness
> -1) {
450 if (cc
->maxStale()==HttpHdrCc::MAX_STALE_ANY
) {
451 debugs(22, 3, "NO: Client accepts a stale response of any age - 'Cache-Control: max-stale'");
452 return FRESH_REQUEST_MAX_STALE_ALL
;
453 } else if (staleness
< cc
->maxStale()) {
454 debugs(22, 3, "NO: Client accepts a stale response - 'Cache-Control: max-stale=" << cc
->maxStale() << "'");
455 return FRESH_REQUEST_MAX_STALE_VALUE
;
461 // If the object is fresh, return the right FRESH_ code
462 if (-1 == staleness
) {
463 debugs(22, 3, "Object isn't stale..");
465 debugs(22, 3, "returning FRESH_EXPIRES");
466 return FRESH_EXPIRES
;
472 debugs(22, 3, "returning FRESH_LMFACTOR_RULE");
473 return FRESH_LMFACTOR_RULE
;
478 debugs(22, 3, "returning FRESH_MIN_RULE");
479 return FRESH_MIN_RULE
;
483 * At this point the response is stale, unless one of
484 * the override options kicks in.
485 * NOTE: max-stale config blocks the overrides.
487 int max_stale
= (R
->max_stale
>= 0 ? R
->max_stale
: Config
.maxStale
);
488 if ( max_stale
>= 0 && staleness
> max_stale
) {
489 debugs(22, 3, "YES: refresh_pattern max-stale=N limit from squid.conf");
491 request
->flags
.failOnValidationError
= true;
492 return STALE_MAX_STALE
;
496 #if USE_HTTP_VIOLATIONS
498 if (R
->flags
.override_expire
&& age
< R
->min
) {
499 debugs(22, 3, "NO: Serving from cache - even though explicit expiry has passed, we enforce Min value (override-expire option)");
500 return FRESH_OVERRIDE_EXPIRES
;
504 return STALE_EXPIRES
;
508 return STALE_MAX_RULE
;
511 #if USE_HTTP_VIOLATIONS
512 if (R
->flags
.override_lastmod
&& age
< R
->min
) {
513 debugs(22, 3, "NO: Serving from cache - even though L-M factor says the object is stale, we enforce Min value (override-lastmod option)");
514 return FRESH_OVERRIDE_LASTMOD
;
517 debugs(22, 3, "YES: L-M factor says the object is stale'");
518 return STALE_LMFACTOR_RULE
;
521 debugs(22, 3, "returning STALE_DEFAULT");
522 return STALE_DEFAULT
;
526 * This is called by http.cc once it has received and parsed the origin server's
527 * response headers. It uses the result as part of its algorithm to decide whether a
528 * response should be cached.
530 * \retval true if the entry is cacheable, regardless of whether FRESH or STALE
531 * \retval false if the entry is not cacheable
533 * TODO: this algorithm seems a bit odd and might not be quite right. Verify against HTTPbis.
536 refreshIsCachable(const StoreEntry
* entry
)
539 * Don't look at the request to avoid no-cache and other nuisances.
540 * the object should have a mem_obj so the URL will be found there.
541 * minimum_expiry_time seconds delta (defaults to 60 seconds), to
542 * avoid objects which expire almost immediately, and which can't
545 int reason
= refreshCheck(entry
, NULL
, Config
.minimum_expiry_time
);
546 ++ refreshCounts
[rcStore
].total
;
547 ++ refreshCounts
[rcStore
].status
[reason
];
549 if (reason
< STALE_MUST_REVALIDATE
)
550 /* Does not need refresh. This is certainly cachable */
553 if (entry
->lastmod
< 0)
554 /* Last modified is needed to do a refresh */
557 if (entry
->mem_obj
== NULL
)
561 if (entry
->getReply() == NULL
)
565 if (entry
->getReply()->content_length
== 0)
566 /* No use refreshing (caching?) 0 byte objects */
569 /* This seems to be refreshable. Cache it */
573 /// whether reply is stale if it is a hit
575 refreshIsStaleIfHit(const int reason
)
579 case FRESH_LMFACTOR_RULE
:
588 * Protocol-specific wrapper around refreshCheck() function.
590 * Note the reason for STALE/FRESH then return true/false respectively.
596 refreshCheckHTTP(const StoreEntry
* entry
, HttpRequest
* request
)
598 int reason
= refreshCheck(entry
, request
, 0);
599 ++ refreshCounts
[rcHTTP
].total
;
600 ++ refreshCounts
[rcHTTP
].status
[reason
];
601 request
->flags
.staleIfHit
= refreshIsStaleIfHit(reason
);
602 return (Config
.onoff
.offline
|| reason
< 200) ? 0 : 1;
605 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
607 refreshCheckICP(const StoreEntry
* entry
, HttpRequest
* request
)
609 int reason
= refreshCheck(entry
, request
, 30);
610 ++ refreshCounts
[rcICP
].total
;
611 ++ refreshCounts
[rcICP
].status
[reason
];
612 return (reason
< 200) ? 0 : 1;
616 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
618 refreshCheckHTCP(const StoreEntry
* entry
, HttpRequest
* request
)
620 int reason
= refreshCheck(entry
, request
, 10);
621 ++ refreshCounts
[rcHTCP
].total
;
622 ++ refreshCounts
[rcHTCP
].status
[reason
];
623 return (reason
< 200) ? 0 : 1;
628 #if USE_CACHE_DIGESTS
629 /// \see int refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request)
631 refreshCheckDigest(const StoreEntry
* entry
, time_t delta
)
633 int reason
= refreshCheck(entry
,
634 entry
->mem_obj
? entry
->mem_obj
->request
: NULL
,
636 ++ refreshCounts
[rcCDigest
].total
;
637 ++ refreshCounts
[rcCDigest
].status
[reason
];
638 return (reason
< 200) ? 0 : 1;
643 * Get the configured maximum caching time for objects with this URL
644 * according to refresh_pattern.
646 * Used by http.cc when generating a upstream requests to ensure that
647 * responses it is given are fresh enough to be worth caching.
649 * \retval pattern-max if there is a refresh_pattern matching the URL configured.
650 * \retval REFRESH_DEFAULT_MAX if there are no explicit limits configured
653 getMaxAge(const char *url
)
655 const RefreshPattern
*R
;
656 debugs(22, 3, "getMaxAge: '" << url
<< "'");
658 if ((R
= refreshLimits(url
)))
661 return REFRESH_DEFAULT_MAX
;
665 refreshCountsStatsEntry(StoreEntry
* sentry
, struct RefreshCounts
&rc
, int code
, const char *desc
)
667 storeAppendPrintf(sentry
, "%6d\t%6.2f\t%s\n", rc
.status
[code
], xpercent(rc
.status
[code
], rc
.total
), desc
);
668 return rc
.status
[code
];
672 refreshCountsStats(StoreEntry
* sentry
, struct RefreshCounts
&rc
)
677 storeAppendPrintf(sentry
, "\n\n%s histogram:\n", rc
.proto
);
678 storeAppendPrintf(sentry
, "Count\t%%Total\tCategory\n");
681 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_REQUEST_MAX_STALE_ALL
, "Fresh: request max-stale wildcard");
682 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_REQUEST_MAX_STALE_VALUE
, "Fresh: request max-stale value");
683 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_EXPIRES
, "Fresh: expires time not reached");
684 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_LMFACTOR_RULE
, "Fresh: refresh_pattern last-mod factor percentage");
685 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_MIN_RULE
, "Fresh: refresh_pattern min value");
686 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_OVERRIDE_EXPIRES
, "Fresh: refresh_pattern override-expires");
687 sum
+= refreshCountsStatsEntry(sentry
, rc
, FRESH_OVERRIDE_LASTMOD
, "Fresh: refresh_pattern override-lastmod");
688 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_MUST_REVALIDATE
, "Stale: response has must-revalidate");
689 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_RELOAD_INTO_IMS
, "Stale: changed reload into IMS");
690 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_FORCED_RELOAD
, "Stale: request has no-cache directive");
691 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
, "Stale: age exceeds request max-age value");
692 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_EXPIRES
, "Stale: expires time reached");
693 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_MAX_RULE
, "Stale: refresh_pattern max age rule");
694 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_LMFACTOR_RULE
, "Stale: refresh_pattern last-mod factor percentage");
695 sum
+= refreshCountsStatsEntry(sentry
, rc
, STALE_DEFAULT
, "Stale: by default");
696 storeAppendPrintf(sentry
, "\n");
700 refreshStats(StoreEntry
* sentry
)
702 // display per-rule counts of usage and tests
703 storeAppendPrintf(sentry
, "\nRefresh pattern usage:\n\n");
704 storeAppendPrintf(sentry
, " Used \tChecks \t%% Matches\tPattern\n");
705 for (const RefreshPattern
*R
= Config
.Refresh
; R
; R
= R
->next
) {
706 storeAppendPrintf(sentry
, " %10" PRIu64
"\t%10" PRIu64
"\t%6.2f\t%s%s\n",
709 xpercent(R
->stats
.matchCount
, R
->stats
.matchTests
),
710 (R
->flags
.icase
? "-i " : ""),
717 /* get total usage count */
719 for (i
= 0; i
< rcCount
; ++i
)
720 total
+= refreshCounts
[i
].total
;
722 /* protocol usage histogram */
723 storeAppendPrintf(sentry
, "\nRefreshCheck calls per protocol\n\n");
725 storeAppendPrintf(sentry
, "Protocol\t#Calls\t%%Calls\n");
727 for (i
= 0; i
< rcCount
; ++i
)
728 storeAppendPrintf(sentry
, "%10s\t%6d\t%6.2f\n",
729 refreshCounts
[i
].proto
,
730 refreshCounts
[i
].total
,
731 xpercent(refreshCounts
[i
].total
, total
));
733 /* per protocol histograms */
734 storeAppendPrintf(sentry
, "\n\nRefreshCheck histograms for various protocols\n");
736 for (i
= 0; i
< rcCount
; ++i
)
737 refreshCountsStats(sentry
, refreshCounts
[i
]);
741 refreshRegisterWithCacheManager(void)
743 Mgr::RegisterAction("refresh", "Refresh Algorithm Statistics", refreshStats
, 0, 1);
749 memset(refreshCounts
, 0, sizeof(refreshCounts
));
750 refreshCounts
[rcHTTP
].proto
= "HTTP";
751 refreshCounts
[rcICP
].proto
= "ICP";
754 refreshCounts
[rcHTCP
].proto
= "HTCP";
757 refreshCounts
[rcStore
].proto
= "On Store";
758 #if USE_CACHE_DIGESTS
760 refreshCounts
[rcCDigest
].proto
= "Cache Digests";
763 memset(&DefaultRefresh
, '\0', sizeof(DefaultRefresh
));
764 DefaultRefresh
.pattern
= "<none>";
765 DefaultRefresh
.min
= REFRESH_DEFAULT_MIN
;
766 DefaultRefresh
.pct
= REFRESH_DEFAULT_PCT
;
767 DefaultRefresh
.max
= REFRESH_DEFAULT_MAX
;
769 refreshRegisterWithCacheManager();