11#ifndef USE_POSIX_REGEX
12#define USE_POSIX_REGEX
95 ++(R->stats.matchTests);
96 if (R->regex().match(url)) {
97 ++(R->stats.matchCount);
110 if (R->regex().isDot())
146 if (entry->
expires > check_time) {
147 debugs(22, 3,
"FRESH: expires " << entry->
expires <<
" > check_time " << check_time);
150 debugs(22, 3,
"STALE: expires " << entry->
expires <<
" <= check_time " << check_time);
151 return (check_time - entry->
expires);
155 debugs(22, 3,
"No explicit expiry given, using heuristics to determine freshness");
159 debugs(22, 3,
"STALE: age " << age <<
" > max " << R->
max);
161 return (age - R->
max);
166 if (lastmod_delta > 0) {
171 time_t stale_age =
static_cast<time_t
>(lastmod_delta * R->
pct);
173 debugs(22,3,
"Last modified " << lastmod_delta <<
" sec before we cached it, L-M factor " <<
174 (100.0 * R->
pct) <<
"% = " << stale_age <<
" sec freshness lifetime");
177 if (age >= stale_age) {
178 debugs(22, 3,
"STALE: age " << age <<
" > stale_age " << stale_age);
179 return (age - stale_age);
181 debugs(22, 3,
"FRESH: age " << age <<
" <= stale_age " << stale_age);
188 debugs(22, 3,
"FRESH: age (" << age <<
" sec) is less than configured minimum (" << R->
min <<
" sec)");
194 debugs(22, 3,
"STALE: No explicit expiry, no last modified, and older than configured minimum.");
195 return (age - R->
min);
261 static const SBuf nilUri(
"<none>");
268 debugs(22, 3,
"checking freshness of " << *entry <<
" with URI: " << uri);
288 debugs(22, 3,
"Matched '" << *R <<
'\'');
290 debugs(22, 3,
"\tage:\t" << age);
300 debugs(22, 3,
"\tage + min-fresh:\t" << age <<
" + " <<
301 minFresh <<
" = " << age + minFresh);
302 debugs(22, 3,
"\tcheck_time + min-fresh:\t" << check_time <<
" + "
303 << minFresh <<
" = " <<
306 check_time += minFresh;
310 memset(&sf,
'\0',
sizeof(sf));
314 debugs(22, 3,
"Staleness = " << staleness);
319 int staleIfError = -1;
322 staleIfError < staleness) {
324 debugs(22, 3,
"stale-if-error period expired. Will produce error if validation fails.");
334 if (revalidateAlways || (staleness > -1 &&
336 debugs(22, 3,
"YES: Must revalidate stale object (origin set " <<
337 (revalidateAlways ?
"no-cache or private" :
338 "must-revalidate, proxy-revalidate or s-maxage") <<
")");
354 debugs(22, 3,
"YES: Client IMS request forcing revalidation of object (refresh-ims option)");
358#if USE_HTTP_VIOLATIONS
385 debugs(22, 3,
"MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
391 debugs(22, 3,
"YES: Client reload request - cheating, only revalidating with origin (reload-into-ims option)");
395 debugs(22, 3,
"YES: Client reload request - fetching new copy from origin");
410 if (reply && reply->cache_control && reply->cache_control->hasImmutable()) {
411 debugs(22, 3,
"MAYBE: Ignoring client CC:max-age=" << maxAge <<
" request - 'Cache-Control: immutable'");
413#if USE_HTTP_VIOLATIONS
416 debugs(22, 3,
"MAYBE: Ignoring client reload request - trying to serve from cache (ignore-reload option)");
420 }
else if (age > maxAge || maxAge == 0) {
421 debugs(22, 3,
"YES: Revalidating object - client 'Cache-Control: max-age=" << maxAge <<
"'");
428 if (cc->
hasMaxStale(&maxStale) && staleness > -1) {
430 debugs(22, 3,
"NO: Client accepts a stale response of any age - 'Cache-Control: max-stale'");
432 }
else if (staleness < maxStale) {
433 debugs(22, 3,
"NO: Client accepts a stale response - 'Cache-Control: max-stale=" << maxStale <<
"'");
441 if (-1 == staleness) {
442 debugs(22, 3,
"Object isn't stale..");
444 debugs(22, 3,
"returning FRESH_EXPIRES");
451 debugs(22, 3,
"returning FRESH_LMFACTOR_RULE");
457 debugs(22, 3,
"returning FRESH_MIN_RULE");
467 if ( max_stale >= 0 && staleness > max_stale) {
468 debugs(22, 3,
"YES: refresh_pattern max-stale=N limit from squid.conf");
475#if USE_HTTP_VIOLATIONS
478 debugs(22, 3,
"NO: Serving from cache - even though explicit expiry has passed, we enforce Min value (override-expire option)");
483 debugs(22, 3,
"returning STALE_EXPIRES");
488 debugs(22, 3,
"returning STALE_MAX_RULE");
493#if USE_HTTP_VIOLATIONS
495 debugs(22, 3,
"NO: Serving from cache - even though L-M factor says the object is stale, we enforce Min value (override-lastmod option)");
499 debugs(22, 3,
"YES: L-M factor says the object is stale'");
503 debugs(22, 3,
"returning STALE_DEFAULT");
598 return (reason < 200) ? 0 : 1;
609 return (reason < 200) ? 0 : 1;
624 return (reason < 200) ? 0 : 1;
642 debugs(22, 3,
"getMaxAge: '" << url <<
"'");
694 xpercent(R->stats.matchCount, R->stats.matchTests));
720 storeAppendPrintf(sentry,
"\n\nRefreshCheck histograms for various protocols\n");
737 regex_->print(os,
nullptr);
748 ' ' << intmax_t(
min/60) <<
749 ' ' << intmax_t(100.0 *
pct + 0.5) <<
'%' <<
750 ' ' << intmax_t(
max/60);
#define REFRESH_DEFAULT_MAX
bool hasMaxStale(int32_t *val=nullptr) const
bool hasMinFresh(int32_t *val=nullptr) const
static const int32_t MAX_STALE_ANY
bool hasMaxAge(int32_t *val=nullptr) const
bool hasStaleIfError(int32_t *val=nullptr) const
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
HttpHdrCc * cache_control
HttpRequestPointer request
const char * storeId() const
const HttpReply & baseReply() const
a representation of a refresh pattern.
struct RefreshPattern::@72 flags
void printPattern(std::ostream &os) const
reports the configured pattern or a fake pattern of the implicit rule
const RegexPattern & regex() const
configured regex; do not use except when iterating configured rules
RegexPointer regex_
configured regex or, for the implicit refresh_pattern rule, nil
void printHead(std::ostream &) const
reports configuration excluding trailing options
bool failOnValidationError
struct SquidConfig::@90 onoff
time_t minimum_expiry_time
void lastModified(const time_t when)
const HttpReply * hasFreshestReply() const
A const & min(A const &lhs, A const &rhs)
#define debugs(SECTION, LEVEL, CONTENT)
#define EBIT_TEST(flag, bit)
@ ENTRY_REVALIDATE_ALWAYS
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
const char * FormatRfc1123(time_t)
time_t getMaxAge(const char *url)
static int refreshCountsStatsEntry(StoreEntry *sentry, struct RefreshCounts &rc, int code, const char *desc)
const RefreshPattern * refreshLimits(const char *url)
int refreshCheckHTCP(const StoreEntry *entry, HttpRequest *request)
static struct RefreshCounts refreshCounts[rcCount]
static int refreshCheck(const StoreEntry *entry, HttpRequest *request, time_t delta)
static void refreshCountsStats(StoreEntry *sentry, struct RefreshCounts &rc)
static int refreshStaleness(const StoreEntry *entry, time_t check_time, const time_t age, const RefreshPattern *R, stale_flags *sf)
int refreshCheckICP(const StoreEntry *entry, HttpRequest *request)
@ FRESH_REQUEST_MAX_STALE_ALL
@ STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
@ FRESH_REQUEST_MAX_STALE_VALUE
bool refreshIsCachable(const StoreEntry *entry)
static bool refreshIsStaleIfHit(const int reason)
whether reply is stale if it is a hit
int refreshCheckDigest(const StoreEntry *entry, time_t delta)
static void refreshRegisterWithCacheManager(void)
static RefreshPattern DefaultRefresh(nullptr)
int refreshCheckHTTP(const StoreEntry *entry, HttpRequest *request)
static const RefreshPattern * refreshFirstDotRule()
the first explicit refresh_pattern rule that uses a "." regex (or nil)
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
int status[STALE_DEFAULT+1]
bool expires
Expires: header absolute timestamp limit.
bool lmfactor
Last-Modified with heuristic determines limit.
bool max
Configured maximum age limit.
bool min
Heuristic minimum age limited.
double xpercent(double part, double whole)