Apache2
Cache Utility Functions
Collaboration diagram for Cache Utility Functions:

Data Structures

struct  cache_enable
 
struct  cache_disable
 
struct  cache_server_conf
 
struct  cache_dir_conf
 
struct  cache_provider_list
 
struct  cache_request_rec
 

Macros

#define APR_WANT_STRFUNC
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define MSEC_ONE_DAY   ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
 
#define MSEC_ONE_HR   ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */
 
#define MSEC_ONE_MIN   ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */
 
#define MSEC_ONE_SEC   ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */
 
#define DEFAULT_CACHE_MAXEXPIRE   MSEC_ONE_DAY
 
#define DEFAULT_CACHE_MINEXPIRE   0
 
#define DEFAULT_CACHE_EXPIRE   MSEC_ONE_HR
 
#define DEFAULT_CACHE_LMFACTOR   (0.1)
 
#define DEFAULT_CACHE_MAXAGE   5
 
#define DEFAULT_X_CACHE   0
 
#define DEFAULT_X_CACHE_DETAIL   0
 
#define DEFAULT_CACHE_STALE_ON_ERROR   1
 
#define DEFAULT_CACHE_LOCKPATH   "mod_cache-lock"
 
#define CACHE_LOCKNAME_KEY   "mod_cache-lockname"
 
#define CACHE_LOCKFILE_KEY   "mod_cache-lockfile"
 
#define CACHE_CTX_KEY   "mod_cache-ctx"
 

Typedefs

typedef struct cache_provider_list cache_provider_list
 

Functions

int ap_cache_check_no_cache (cache_request_rec *cache, request_rec *r)
 
int ap_cache_check_no_store (cache_request_rec *cache, request_rec *r)
 
int cache_check_freshness (cache_handle_t *h, cache_request_rec *cache, request_rec *r)
 
apr_status_t cache_try_lock (cache_server_conf *conf, cache_request_rec *cache, request_rec *r)
 
apr_status_t cache_remove_lock (cache_server_conf *conf, cache_request_rec *cache, request_rec *r, apr_bucket_brigade *bb)
 
cache_provider_listcache_get_providers (request_rec *r, cache_server_conf *conf)
 
const char * cache_table_getm (apr_pool_t *p, const apr_table_t *t, const char *key)
 
apr_status_t cache_strqtok (char *str, char **token, char **arg, char **last)
 
apr_table_tcache_merge_headers_out (request_rec *r)
 
int cache_use_early_url (request_rec *r)
 

Detailed Description

Macro Definition Documentation

◆ APR_WANT_STRFUNC

#define APR_WANT_STRFUNC

◆ CACHE_CTX_KEY

#define CACHE_CTX_KEY   "mod_cache-ctx"

◆ CACHE_LOCKFILE_KEY

#define CACHE_LOCKFILE_KEY   "mod_cache-lockfile"

◆ CACHE_LOCKNAME_KEY

#define CACHE_LOCKNAME_KEY   "mod_cache-lockname"

◆ DEFAULT_CACHE_EXPIRE

#define DEFAULT_CACHE_EXPIRE   MSEC_ONE_HR

◆ DEFAULT_CACHE_LMFACTOR

#define DEFAULT_CACHE_LMFACTOR   (0.1)

◆ DEFAULT_CACHE_LOCKPATH

#define DEFAULT_CACHE_LOCKPATH   "mod_cache-lock"

◆ DEFAULT_CACHE_MAXAGE

#define DEFAULT_CACHE_MAXAGE   5

◆ DEFAULT_CACHE_MAXEXPIRE

#define DEFAULT_CACHE_MAXEXPIRE   MSEC_ONE_DAY

◆ DEFAULT_CACHE_MINEXPIRE

#define DEFAULT_CACHE_MINEXPIRE   0

◆ DEFAULT_CACHE_STALE_ON_ERROR

#define DEFAULT_CACHE_STALE_ON_ERROR   1

◆ DEFAULT_X_CACHE

#define DEFAULT_X_CACHE   0

◆ DEFAULT_X_CACHE_DETAIL

#define DEFAULT_X_CACHE_DETAIL   0

◆ MAX

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

◆ MSEC_ONE_DAY

#define MSEC_ONE_DAY   ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */

◆ MSEC_ONE_HR

#define MSEC_ONE_HR   ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */

◆ MSEC_ONE_MIN

#define MSEC_ONE_MIN   ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */

◆ MSEC_ONE_SEC

#define MSEC_ONE_SEC   ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */

Typedef Documentation

◆ cache_provider_list

Function Documentation

◆ ap_cache_check_no_cache()

int ap_cache_check_no_cache ( cache_request_rec cache,
request_rec r 
)

Check the whether the request allows a cached object to be served as per RFC2616 section 14.9.4 (Cache Revalidation and Reload Controls)

Parameters
cachecache_request_rec
rrequest_rec
Returns
0 ==> cache object may not be served, 1 ==> cache object may be served

◆ ap_cache_check_no_store()

int ap_cache_check_no_store ( cache_request_rec cache,
request_rec r 
)

Check the whether the request allows a cached object to be stored as per RFC2616 section 14.9.2 (What May be Stored by Caches)

Parameters
cachecache_request_rec
rrequest_rec
Returns
0 ==> cache object may not be served, 1 ==> cache object may be served

◆ cache_check_freshness()

int cache_check_freshness ( cache_handle_t h,
cache_request_rec cache,
request_rec r 
)

Check the freshness of the cache object per RFC2616 section 13.2 (Expiration Model)

Parameters
hcache_handle_t
cachecache_request_rec
rrequest_rec
Returns
0 ==> cache object is stale, 1 ==> cache object is fresh

◆ cache_get_providers()

cache_provider_list* cache_get_providers ( request_rec r,
cache_server_conf conf 
)

◆ cache_merge_headers_out()

apr_table_t* cache_merge_headers_out ( request_rec r)

Merge err_headers_out into headers_out and add request's Content-Type and Content-Encoding if available.

◆ cache_remove_lock()

apr_status_t cache_remove_lock ( cache_server_conf conf,
cache_request_rec cache,
request_rec r,
apr_bucket_brigade bb 
)

Remove the cache lock, if present.

First, try to close the file handle, whose delete-on-close should kill the file. Otherwise, just delete the file by name.

If no lock name has yet been calculated, do the calculation of the lock name first before trying to delete the file.

If an optional bucket brigade is passed, the lock will only be removed if the bucket brigade contains an EOS bucket.

◆ cache_strqtok()

apr_status_t cache_strqtok ( char *  str,
char **  token,
char **  arg,
char **  last 
)

String tokenizer per RFC 7234 section 5.2 (1#token[=["]arg["]]). If any (and arg not NULL), the argument is also returned (unquoted).

◆ cache_table_getm()

const char* cache_table_getm ( apr_pool_t p,
const apr_table_t t,
const char *  key 
)

Get a value from a table, where the table may contain multiple values for a given key.

When the table contains a single value, that value is returned unchanged.

When the table contains two or more values for a key, all values for the key are returned, separated by commas.

◆ cache_try_lock()

apr_status_t cache_try_lock ( cache_server_conf conf,
cache_request_rec cache,
request_rec r 
)

Try obtain a cache wide lock on the given cache key.

If we return APR_SUCCESS, we obtained the lock, and we are clear to proceed to the backend. If we return APR_EEXISTS, then the lock is already locked, someone else has gone to refresh the backend data already, so we must return stale data with a warning in the mean time. If we return anything else, then something has gone pear shaped, and we allow the request through to the backend regardless.

This lock is created from the request pool, meaning that should something go wrong and the lock isn't deleted on return of the request headers from the backend for whatever reason, at worst the lock will be cleaned up when the request is dies or finishes.

If something goes truly bananas and the lock isn't deleted when the request dies, the lock will be trashed when its max-age is reached, or when a request arrives containing a Cache-Control: no-cache. At no point is it possible for this lock to permanently deny access to the backend.

◆ cache_use_early_url()

int cache_use_early_url ( request_rec r)

Return whether to use request's path/query from early stage (r->parsed_uri) or the current/rewritable ones (r->uri/r->args).