mod_cache.h revision 6dafbe869f4b41302bf981039e1294edd5eaf422
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* Licensed to the Apache Software Foundation (ASF) under one or more
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * contributor license agreements. See the NOTICE file distributed with
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * this work for additional information regarding copyright ownership.
0a05fab9aadd37834734ffe106fc8ad4488fb3e3rbowen * The ASF licenses this file to You under the Apache License, Version 2.0
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * (the "License"); you may not use this file except in compliance with
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * the License. You may obtain a copy of the License at
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * Unless required by applicable law or agreed to in writing, software
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * distributed under the License is distributed on an "AS IS" BASIS,
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * See the License for the specific language governing permissions and
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * limitations under the License.
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * @brief Main include file for the Apache Transparent Cache
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * @defgroup MOD_CACHE mod_cache
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * @ingroup APACHE_MODS
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define MAX(a,b) ((a) > (b) ? (a) : (b))
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define MIN(a,b) ((a) < (b) ? (a) : (b))
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define MSEC_ONE_DAY ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define MSEC_ONE_HR ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and
d89089206f40f9a6d58528ff85050447d4a52d53lgentis * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
d89089206f40f9a6d58528ff85050447d4a52d53lgentis#if !defined(WIN32)
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor const char *type;
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* static information about the local cache */
d89089206f40f9a6d58528ff85050447d4a52d53lgentistypedef struct {
d89089206f40f9a6d58528ff85050447d4a52d53lgentis apr_array_header_t *cacheenable; /* URLs to cache */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis apr_array_header_t *cachedisable; /* URLs not to cache */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis /* Maximum time to keep cached files in msecs */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /* default time to keep cached file in msecs */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /* factor for estimating expires date */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis /** ignore the last-modified header when deciding to cache this request */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** ignore client's requests for uncached responses */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** ignore Cache-Control: private header from server */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** ignore Cache-Control: no-store header from client or server */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** store the headers that should not be stored in the cache */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /* flag if CacheIgnoreHeader has been set */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /* Minimum time to keep cached files in msecs */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** ignore query-string when caching */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* cache info information */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * HTTP status code of the cached entity. Though not neccessarily the
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * status code finally issued to the request.
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * the original time corresponding to the 'Date:' header of the request
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** a time when the cached entity is due to expire */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** r->request_time from the same request */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /** apr_time_now() at the time the entity was acutally cached */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* cache handle information */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* XXX TODO On the next structure change/MMN bump,
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * count must become an apr_off_t, representing
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * the potential size of disk cached objects.
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * Then dig for
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * "XXX Bad Temporary Cast - see cache_object_t notes"
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor const char *key;
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /* Opaque portion (specific to the implementation) of the cache object */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor /* FIXME: These are only required for mod_mem_cache. */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_size_t count; /* Number of body bytes written to the cache so far */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_uint32_t refcount; /* refcount and bit flag to cleanup object */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_table_t *resp_hdrs; /* cached response headers */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzortypedef struct {
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_status_t (*store_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_status_t (*store_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *b);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_status_t (*recall_headers) (cache_handle_t *h, request_rec *r);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor apr_status_t (*recall_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor int (*create_entity) (cache_handle_t *h, request_rec *r,
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor int (*open_entity) (cache_handle_t *h, request_rec *r,
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor const char *urlkey);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor int (*remove_url) (cache_handle_t *h, apr_pool_t *p);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* A linked-list of authn providers. */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzortypedef struct cache_provider_list cache_provider_list;
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* per request cache information */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzortypedef struct {
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor cache_provider_list *providers; /* possible cache providers */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor const cache_provider *provider; /* current cache provider */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor const char *provider_name; /* current cache provider name */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis cache_handle_t *stale_handle; /* stale cache handle */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis apr_table_t *stale_headers; /* original request headers. */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis int in_checked; /* CACHE_SAVE must cache the entity */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis int block_response; /* CACHE_SAVE must block response. */
d89089206f40f9a6d58528ff85050447d4a52d53lgentis apr_bucket_brigade *saved_brigade; /* copy of partial response */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor ap_filter_t *remove_url_filter; /* Enable us to remove the filter */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor/* do a HTTP/1.1 age calculation */
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorCACHE_DECLARE(apr_time_t) ap_cache_current_age(cache_info *info, const apr_time_t age_value,
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * Check the freshness of the cache object per RFC2616 section 13.2 (Expiration Model)
576c49cd335618ad4b5351bd1c5f2cfd7584dba4lgentis * @param h cache_handle_t
576c49cd335618ad4b5351bd1c5f2cfd7584dba4lgentis * @param r request_rec
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * @return 0 ==> cache object is stale, 1 ==> cache object is fresh
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorCACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, request_rec *r);
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentis * Merge in cached headers into the response
1b1b6ae3d9cf8a22cd74249fe56d4fab443f9e21lgentis * @param h cache_handle_t
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentis * @param r request_rec
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentis * @param preserve_orig If 1, the values in r->headers_out are preserved.
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentis * Otherwise, they are overwritten by the cached value.
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(void) ap_cache_accept_headers(cache_handle_t *h, request_rec *r,
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(apr_time_t) ap_cache_hex2usec(const char *x);
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y);
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels,
21b0af80656190938e7dd1d9b0a83dc803626824lgentis const char *name);
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf *conf, apr_uri_t uri);
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list,
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
aca6eead4bc5fed9b497b0ca21027c1bcba56054lgentis/* Create a new table consisting of those elements from an
d89089206f40f9a6d58528ff85050447d4a52d53lgentis * headers table that are allowed to be stored in a cache.
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers(apr_pool_t *pool,
1b1b6ae3d9cf8a22cd74249fe56d4fab443f9e21lgentis/* Create a new table consisting of those elements from an input
1b1b6ae3d9cf8a22cd74249fe56d4fab443f9e21lgentis * headers table that are allowed to be stored in a cache.
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_in(request_rec *r);
1b1b6ae3d9cf8a22cd74249fe56d4fab443f9e21lgentis/* Create a new table consisting of those elements from an output
d89089206f40f9a6d58528ff85050447d4a52d53lgentis * headers table that are allowed to be stored in a cache;
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentis * ensure there is a content type and capture any errors.
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_out(request_rec *r);
21b0af80656190938e7dd1d9b0a83dc803626824lgentis/* Legacy call - functionally equivalent to ap_cache_cacheable_headers.
21b0af80656190938e7dd1d9b0a83dc803626824lgentis * @deprecated @see ap_cache_cacheable_headers
560024d8ef457c288c07cee03dd8db0ab28c2fb8lgentisCACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool,
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorint cache_remove_url(cache_request_rec *cache, apr_pool_t *p);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorint cache_create_entity(request_rec *r, apr_off_t size);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorapr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * create a key for the cache based on the request record
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor * this is the 'default' version, which can be overridden by a default function
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorapr_status_t cache_store_entity_headers(cache_handle_t *h, request_rec *r, cache_info *info);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorapr_status_t cache_store_entity_body(cache_handle_t *h, request_rec *r, apr_bucket_brigade *bb);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzorapr_status_t cache_recall_entity_headers(cache_handle_t *h, request_rec *r);
d89089206f40f9a6d58528ff85050447d4a52d53lgentisapr_status_t cache_recall_entity_body(cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
fbad7185dd78ec6e09c5b191693deda9d4bfa08cgryzor#endif /*MOD_CACHE_H*/