cache_util.h revision 4cefc38158672f5de8119886d9754cf0609a9371
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file cache_util.h
* @brief Cache Storage Functions
*
* @defgroup Cache_util Cache Utility Functions
* @ingroup MOD_CACHE
* @{
*/
#ifndef CACHE_UTIL_H
#define CACHE_UTIL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "mod_cache.h"
#include "apr_hooks.h"
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_md5.h"
#include "apr_pools.h"
#include "apr_strings.h"
#include "apr_optional.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "httpd.h"
#include "http_config.h"
#include "ap_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_vhost.h"
#include "http_main.h"
#include "http_log.h"
#include "http_connection.h"
#include "util_filter.h"
#include "apr_uri.h"
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#endif
#ifdef HAVE_NETINET_IN_H
#endif
#ifdef HAVE_ARPA_INET_H
#endif
#include "apr_atomic.h"
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#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_LOCKPATH "/mod_cache-lock"
#define CACHE_LOCKNAME_KEY "mod_cache-lockname"
#define CACHE_LOCKFILE_KEY "mod_cache-lockfile"
/**
*/
struct cache_enable {
const char *type;
};
struct cache_disable {
};
/* static information about the local cache */
typedef struct {
/** ignore client's requests for uncached responses */
int ignorecachecontrol;
/* flag if CacheIgnoreHeader has been set */
#define CACHE_IGNORE_HEADERS_SET 1
#define CACHE_IGNORE_HEADERS_UNSET 0
int ignore_headers_set;
/** store the headers that should not be stored in the cache */
/** ignore query-string when caching */
int ignorequerystring;
/* flag if CacheIgnoreURLSessionIdentifiers has been set */
#define CACHE_IGNORE_SESSION_ID_SET 1
#define CACHE_IGNORE_SESSION_ID_UNSET 0
/** store the identifiers that should not be used for key calculation */
/* thundering herd lock */
int lock;
int lock_set;
const char *lockpath;
int lockpath_set;
int lockmaxage_set;
/** run within the quick handler */
int quick;
int quick_set;
int x_cache;
int x_cache_set;
int x_cache_detail;
int x_cache_detail_set;
typedef struct {
/** ignore the last-modified header when deciding to cache this request */
int no_last_mod_ignore;
/** ignore expiration date from server */
int store_expired;
int store_expired_set;
/** ignore Cache-Control: private header from server */
int store_private;
int store_private_set;
/** ignore Cache-Control: no-store header from client or server */
int store_nostore;
int store_nostore_set;
/* Minimum time to keep cached files in msecs */
int minex_set;
/* Maximum time to keep cached files in msecs */
int maxex_set;
/* default time to keep cached file in msecs */
int defex_set;
/* factor for estimating expires date */
double factor;
int factor_set;
/* set X-Cache headers */
int x_cache;
int x_cache_set;
int x_cache_detail;
int x_cache_detail_set;
/* A linked-list of authn providers. */
typedef struct cache_provider_list cache_provider_list;
struct cache_provider_list {
const char *provider_name;
const cache_provider *provider;
};
/* per request cache information */
typedef struct {
const char *provider_name; /* current cache provider name */
int fresh; /* is the entity fresh? */
int in_checked; /* CACHE_SAVE must cache the entity */
int block_response; /* CACHE_SAVE must block response. */
const char *key; /* The cache key created for this
* request
*/
/**
* Check the freshness of the cache object per RFC2616 section 13.2 (Expiration Model)
* @param h cache_handle_t
* @param r request_rec
* @return 0 ==> cache object is stale, 1 ==> cache object is fresh
*/
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, the 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.
*/
/**
* 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.
*/
#ifdef __cplusplus
}
#endif
#endif /* !CACHE_UTIL_H */
/** @} */