refresh.cc File Reference
#include "squid.h"
#include "HttpHdrCc.h"
#include "HttpReply.h"
#include "HttpRequest.h"
#include "MemObject.h"
#include "mgr/Registration.h"
#include "RefreshPattern.h"
#include "SquidConfig.h"
#include "SquidTime.h"
#include "Store.h"
#include "util.h"
Include dependency graph for refresh.cc:

Go to the source code of this file.

Classes

struct  stale_flags
 
struct  RefreshCounts
 

Macros

#define USE_POSIX_REGEX   /* put before includes; always use POSIX */
 

Enumerations

enum  refreshCountsEnum {
  rcHTTP,
  rcICP,
  rcHTCP,
  rcCDigest,
  rcStore,
  rcCount
}
 
enum  {
  FRESH_REQUEST_MAX_STALE_ALL = 100,
  FRESH_REQUEST_MAX_STALE_VALUE,
  FRESH_EXPIRES,
  FRESH_LMFACTOR_RULE,
  FRESH_MIN_RULE,
  FRESH_OVERRIDE_EXPIRES,
  FRESH_OVERRIDE_LASTMOD,
  STALE_MUST_REVALIDATE = 200,
  STALE_RELOAD_INTO_IMS,
  STALE_FORCED_RELOAD,
  STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE,
  STALE_EXPIRES,
  STALE_MAX_RULE,
  STALE_LMFACTOR_RULE,
  STALE_MAX_STALE,
  STALE_DEFAULT = 299
}
 

Functions

static const RefreshPatternrefreshUncompiledPattern (const char *)
 
static int refreshStaleness (const StoreEntry *entry, time_t check_time, const time_t age, const RefreshPattern *R, stale_flags *sf)
 
const RefreshPatternrefreshLimits (const char *url)
 
static int refreshCheck (const StoreEntry *entry, HttpRequest *request, time_t delta)
 
bool refreshIsCachable (const StoreEntry *entry)
 
static bool refreshIsStaleIfHit (const int reason)
 whether reply is stale if it is a hit More...
 
int refreshCheckHTTP (const StoreEntry *entry, HttpRequest *request)
 
int refreshCheckICP (const StoreEntry *entry, HttpRequest *request)
 
int refreshCheckHTCP (const StoreEntry *entry, HttpRequest *request)
 
int refreshCheckDigest (const StoreEntry *entry, time_t delta)
 
time_t getMaxAge (const char *url)
 
static int refreshCountsStatsEntry (StoreEntry *sentry, struct RefreshCounts &rc, int code, const char *desc)
 
static void refreshCountsStats (StoreEntry *sentry, struct RefreshCounts &rc)
 
static void refreshStats (StoreEntry *sentry)
 
static void refreshRegisterWithCacheManager (void)
 
void refreshInit (void)
 

Variables

static struct RefreshCounts refreshCounts [rcCount]
 
static OBJH refreshStats
 
static RefreshPattern DefaultRefresh ("<none>", 0)
 

Macro Definition Documentation

◆ USE_POSIX_REGEX

#define USE_POSIX_REGEX   /* put before includes; always use POSIX */

Definition at line 12 of file refresh.cc.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FRESH_REQUEST_MAX_STALE_ALL 
FRESH_REQUEST_MAX_STALE_VALUE 
FRESH_EXPIRES 
FRESH_LMFACTOR_RULE 
FRESH_MIN_RULE 
FRESH_OVERRIDE_EXPIRES 
FRESH_OVERRIDE_LASTMOD 
STALE_MUST_REVALIDATE 
STALE_RELOAD_INTO_IMS 
STALE_FORCED_RELOAD 
STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE 
STALE_EXPIRES 
STALE_MAX_RULE 
STALE_LMFACTOR_RULE 
STALE_MAX_STALE 
STALE_DEFAULT 

Definition at line 56 of file refresh.cc.

◆ refreshCountsEnum

Enumerator
rcHTTP 
rcICP 
rcHTCP 
rcCDigest 
rcStore 
rcCount 

Definition at line 27 of file refresh.cc.

Function Documentation

◆ getMaxAge()

time_t getMaxAge ( const char *  url)

Get the configured maximum caching time for objects with this URL according to refresh_pattern.

Used by http.cc when generating a upstream requests to ensure that responses it is given are fresh enough to be worth caching.

Return values
pattern-maxif there is a refresh_pattern matching the URL configured.
REFRESH_DEFAULT_MAXif there are no explicit limits configured

Definition at line 646 of file refresh.cc.

References debugs, RefreshPattern::max, REFRESH_DEFAULT_MAX, and refreshLimits().

Referenced by HttpStateData::httpBuildRequestHeader().

◆ refreshCheck()

static int refreshCheck ( const StoreEntry entry,
HttpRequest request,
time_t  delta 
)
static

Checks whether a store entry is fresh or stale, and why.

This is where all aspects of request, response and squid configuration meet to decide whether a response is cacheable or not:

  1. Client request headers that affect cacheability, e.g.
    • Cache-Control: no-cache
    • Cache-Control: max-age=N
    • Cache-Control: max-stale[=N]
    • Pragma: no-cache
  2. Server response headers that affect cacheability, e.g.
    • Age:
    • Cache-Control: proxy-revalidate
    • Cache-Control: must-revalidate
    • Cache-Control: no-cache
    • Cache-Control: max-age=N
    • Cache-Control: s-maxage=N
    • Date:
    • Expires:
    • Last-Modified:
  3. Configuration options, e.g.
    • reload-into-ims (refresh_pattern)
    • ignore-reload (refresh_pattern)
    • refresh-ims (refresh_pattern)
    • override-lastmod (refresh_pattern)
    • override-expire (refresh_pattern)
    • reload_into_ims (global option)
    • refresh_all_ims (global option)
Returns
a status code (from enum above):
  • FRESH_REQUEST_MAX_STALE_ALL
  • FRESH_REQUEST_MAX_STALE_VALUE
  • FRESH_EXPIRES
  • FRESH_LMFACTOR_RULE
  • FRESH_MIN_RULE
  • FRESH_OVERRIDE_EXPIRES
  • FRESH_OVERRIDE_LASTMOD
  • STALE_MUST_REVALIDATE
  • STALE_RELOAD_INTO_IMS
  • STALE_FORCED_RELOAD
  • STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE
  • STALE_EXPIRES
  • STALE_MAX_RULE
  • STALE_LMFACTOR_RULE
  • STALE_MAX_STALE
  • STALE_DEFAULT
Note
request may be NULL (e.g. for cache digests build)
the store entry being examined is not necessarily cached (e.g. if this response is being evaluated for the first time)

Definition at line 264 of file refresh.cc.

References assert, RegexPattern::c_str(), SBuf::c_str(), Http::Message::cache_control, Config, debugs, DefaultRefresh, EBIT_TEST, HttpRequest::effectiveRequestUri(), ENTRY_REVALIDATE_ALWAYS, ENTRY_REVALIDATE_STALE, stale_flags::expires, RequestFlags::failOnValidationError, RefreshPattern::flags, HttpRequest::flags, StoreEntry::flags, FRESH_EXPIRES, FRESH_LMFACTOR_RULE, FRESH_MIN_RULE, FRESH_OVERRIDE_EXPIRES, FRESH_OVERRIDE_LASTMOD, FRESH_REQUEST_MAX_STALE_ALL, FRESH_REQUEST_MAX_STALE_VALUE, MemObject::getReply(), HttpHdrCc::hasMaxAge(), HttpHdrCc::hasMaxStale(), HttpHdrCc::hasMinFresh(), HttpHdrCc::hasStaleIfError(), RefreshPattern::ignore_reload, RequestFlags::ignoreCc, RequestFlags::ims, int, stale_flags::lmfactor, stale_flags::max, RefreshPattern::max, RefreshPattern::max_stale, HttpHdrCc::MAX_STALE_ANY, SquidConfig::maxStale, StoreEntry::mem_obj, stale_flags::min, RefreshPattern::min, min(), mkrfc1123(), RequestFlags::noCache, RequestFlags::noCacheHack(), NULL, SquidConfig::onoff, RefreshPattern::override_expire, RefreshPattern::override_lastmod, RefreshPattern::pattern, RefreshPattern::pct, SquidConfig::refresh_all_ims, RefreshPattern::refresh_ims, refreshLimits(), refreshStaleness(), refreshUncompiledPattern(), RefreshPattern::reload_into_ims, SquidConfig::reload_into_ims, squid_curtime, STALE_DEFAULT, STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE, STALE_EXPIRES, STALE_FORCED_RELOAD, STALE_LMFACTOR_RULE, STALE_MAX_RULE, STALE_MAX_STALE, STALE_MUST_REVALIDATE, STALE_RELOAD_INTO_IMS, MemObject::storeId(), StoreEntry::timestamp, and ClientHttpRequest::uri.

Referenced by refreshCheckDigest(), refreshCheckHTCP(), refreshCheckHTTP(), refreshCheckICP(), and refreshIsCachable().

◆ refreshCheckDigest()

◆ refreshCheckHTCP()

int refreshCheckHTCP ( const StoreEntry entry,
HttpRequest request 
)

◆ refreshCheckHTTP()

int refreshCheckHTTP ( const StoreEntry entry,
HttpRequest request 
)

Protocol-specific wrapper around refreshCheck() function.

Note the reason for STALE/FRESH then return true/false respectively.

Return values
1if STALE
0if FRESH

Definition at line 588 of file refresh.cc.

References Config, HttpRequest::flags, SquidConfig::offline, SquidConfig::onoff, rcHTTP, refreshCheck(), refreshCounts, refreshIsStaleIfHit(), RequestFlags::staleIfHit, RefreshCounts::status, and RefreshCounts::total.

Referenced by clientReplyContext::cacheHit().

◆ refreshCheckICP()

◆ refreshCountsStats()

◆ refreshCountsStatsEntry()

static int refreshCountsStatsEntry ( StoreEntry sentry,
struct RefreshCounts rc,
int  code,
const char *  desc 
)
static

Definition at line 658 of file refresh.cc.

References code, RefreshCounts::status, storeAppendPrintf(), RefreshCounts::total, and xpercent().

Referenced by refreshCountsStats().

◆ refreshInit()

void refreshInit ( void  )

◆ refreshIsCachable()

bool refreshIsCachable ( const StoreEntry entry)

This is called by http.cc once it has received and parsed the origin server's response headers. It uses the result as part of its algorithm to decide whether a response should be cached.

Return values
trueif the entry is cacheable, regardless of whether FRESH or STALE
falseif the entry is not cacheable

TODO: this algorithm seems a bit odd and might not be quite right. Verify against HTTPbis.

Definition at line 528 of file refresh.cc.

References Config, Http::Message::content_length, StoreEntry::getReply(), StoreEntry::lastModified(), StoreEntry::mem_obj, SquidConfig::minimum_expiry_time, NULL, rcStore, refreshCheck(), refreshCounts, STALE_MUST_REVALIDATE, RefreshCounts::status, and RefreshCounts::total.

Referenced by HttpStateData::reusableReply().

◆ refreshIsStaleIfHit()

static bool refreshIsStaleIfHit ( const int  reason)
static

Definition at line 567 of file refresh.cc.

References FRESH_EXPIRES, FRESH_LMFACTOR_RULE, and FRESH_MIN_RULE.

Referenced by refreshCheckHTTP().

◆ refreshLimits()

const RefreshPattern* refreshLimits ( const char *  url)

Locate the first refresh_pattern rule that matches the given URL by regex.

Returns
A pointer to the refresh_pattern parameters to use, or nullptr if there is no match.

Definition at line 92 of file refresh.cc.

References Config, RefreshPattern::next, and SquidConfig::Refresh.

Referenced by getMaxAge(), and refreshCheck().

◆ refreshRegisterWithCacheManager()

static void refreshRegisterWithCacheManager ( void  )
static

Definition at line 734 of file refresh.cc.

References refreshStats, and Mgr::RegisterAction().

Referenced by refreshInit().

◆ refreshStaleness()

static int refreshStaleness ( const StoreEntry entry,
time_t  check_time,
const time_t  age,
const RefreshPattern R,
stale_flags sf 
)
static

Calculate how stale the response is (or will be at the check_time).

We try the following ways until one gives a result:

  1. response expiration time, if one was set
  2. age greater than configured maximum
  3. last-modified factor algorithm
  4. age less than configured minimum
  5. default (stale)
Parameters
entrythe StoreEntry being examined
check_timethe time (maybe future) at which we want to know whether $
agethe age of the entry at check_time
Rthe refresh_pattern rule that matched this entry
sfsmall struct to indicate reason for stale/fresh decision
Return values
-1If the response is fresh.
>0The amount of staleness.
0NOTE return value of 0 means the response is stale.

Definition at line 146 of file refresh.cc.

References debugs, stale_flags::expires, StoreEntry::expires, StoreEntry::lastModified(), stale_flags::lmfactor, stale_flags::max, RefreshPattern::max, stale_flags::min, RefreshPattern::min, min(), RefreshPattern::pct, and StoreEntry::timestamp.

Referenced by refreshCheck().

◆ refreshStats()

static void refreshStats ( StoreEntry sentry)
static

◆ refreshUncompiledPattern()

static const RefreshPattern * refreshUncompiledPattern ( const char *  pat)
static

Locate the first refresh_pattern rule that has the given uncompiled regex.

Note
There is only one reference to this function, below. It always passes "." as the pattern. This function is only ever called if there is no URI. Because a regex match is impossible, Squid forces the "." rule to apply (if it exists)
Returns
A pointer to the refresh_pattern parameters to use, or nullptr if there is no match.

Definition at line 114 of file refresh.cc.

References Config, RefreshPattern::next, and SquidConfig::Refresh.

Referenced by refreshCheck().

Variable Documentation

◆ DefaultRefresh

RefreshPattern DefaultRefresh("<none>", 0)
static

Referenced by refreshCheck().

◆ refreshCounts

◆ refreshStats

OBJH refreshStats
static

Definition at line 82 of file refresh.cc.

Referenced by refreshRegisterWithCacheManager().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors