mod_cache.h revision c49200a2bdbb8fa1f2e5c3b87cc497ecdeefa8fe
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* ====================================================================
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * The Apache Software License, Version 1.1
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Redistribution and use in source and binary forms, with or without
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * modification, are permitted provided that the following conditions
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 1. Redistributions of source code must retain the above copyright
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * notice, this list of conditions and the following disclaimer.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 2. Redistributions in binary form must reproduce the above copyright
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * notice, this list of conditions and the following disclaimer in
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * the documentation and/or other materials provided with the
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * distribution.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 3. The end-user documentation included with the redistribution,
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * if any, must include the following acknowledgment:
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * "This product includes software developed by the
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Apache Software Foundation (http://www.apache.org/)."
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * Alternately, this acknowledgment may appear in the software itself,
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * if and wherever such third-party acknowledgments normally appear.
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen * 4. The names "Apache" and "Apache Software Foundation" must
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * not be used to endorse or promote products derived from this
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen * software without prior written permission. For written
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * permission, please contact apache@apache.org.
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainen * 5. Products derived from this software may not be called "Apache",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * nor may "Apache" appear in their name, without prior written
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * permission of the Apache Software Foundation.
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen * SUCH DAMAGE.
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen * ====================================================================
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen * This software consists of voluntary contributions made by many
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen * individuals on behalf of the Apache Software Foundation. For more
d5bae4060a1ba3fe663991169de7102f81039304Timo Sirainen * information on the Apache Software Foundation, please see
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Portions of this software are based upon public domain software
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * originally written at the National Center for Supercomputing Applications,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * University of Illinois, Urbana-Champaign.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Main include file for the Apache Transparent Cache
38da5c23b0a8b4012e79fcf647a8749786c83c51Timo Sirainen#define MAX(a,b) ((a) > (b) ? (a) : (b))
b7b81543899e306c71e6152516d8698416162bcbTimo Sirainen#define MIN(a,b) ((a) < (b) ? (a) : (b))
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* default completion is 60% */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MSEC_ONE_DAY ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MSEC_ONE_HR ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */
dc4e0821e709d93c8504e50b4ba0aaeb5ce9e032Timo Sirainen#define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */
43f6755bda8c834bf7a7120e6b485c35e27ee8bdTimo Sirainen#define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
aba2f05e938a7f635b3f114d56c7c3413ee858feTimo Sirainen * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen#define CACHE_DECLARE_DATA __declspec(dllexport)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen#define CACHE_DECLARE_DATA __declspec(dllimport)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen const char *url;
eb99fc24b7d1b2abb6b9217e2b732595069c908eTimo Sirainen const char *url;
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen/* static information about the local cache */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainentypedef struct {
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_array_header_t *cacheenable; /* URLs to cache */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_array_header_t *cachedisable; /* URLs not to cache */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_time_t maxex; /* Maximum time to keep cached files in msecs */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen apr_time_t defex; /* default time to keep cached file in msecs */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen double factor; /* factor for estimating expires date */
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen int complete; /* Force cache completion after this point */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /** ignore the last-modified header when deciding to cache this request */
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen /** ignore client's requests for uncached responses */
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen/* cache info information */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen char *lastmods; /* last modified of cache entity */
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen/* cache handle information */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void *vobj; /* Opaque portion (specific to the cache implementation) of the cache object */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen apr_size_t count; /* Number of body bytes written to the cache so far */
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen apr_status_t (*write_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen apr_status_t (*write_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *b);
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen apr_status_t (*read_headers) (cache_handle_t *h, request_rec *r);
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen apr_status_t (*read_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen/* per request cache information */
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainentypedef struct {
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen const char *types; /* the types of caches allowed */
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainen const char *type; /* the type of cache selected */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen cache_handle_t *handle; /* current cache handle */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen int in_checked; /* CACHE_IN must cache the entity */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo SirainenCACHE_DECLARE(apr_time_t) ap_cache_hex2msec(const char *x);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo SirainenCACHE_DECLARE(void) ap_cache_msec2hex(apr_time_t j, char *y);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo SirainenCACHE_DECLARE(char *) generate_name(apr_pool_t *p, int dirlevels,
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo Sirainen const char *name);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo SirainenCACHE_DECLARE(int) ap_cache_request_is_conditional(request_rec *r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo SirainenCACHE_DECLARE(void) ap_cache_reset_output_filters(request_rec *r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo SirainenCACHE_DECLARE(const char *)ap_cache_get_cachetype(request_rec *r, cache_server_conf *conf, const char *url);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo SirainenCACHE_DECLARE(int) ap_cache_liststr(const char *list, const char *key, char **val);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo SirainenCACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
de7611687432b9560bdd31a4969609e7b68a5b83Timo Sirainenint cache_remove_url(request_rec *r, const char *types, char *url);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint cache_create_entity(request_rec *r, const char *types, char *url, apr_size_t size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint cache_remove_entity(request_rec *r, const char *types, cache_handle_t *h);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenint cache_select_url(request_rec *r, const char *types, char *url);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenapr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen * create a key for the cache based on the request record
d22301419109ed4a38351715e6760011421dadecTimo Sirainen * this is the 'default' version, which can be overridden by a default function
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenapr_status_t cache_write_entity_headers(cache_handle_t *h, request_rec *r, cache_info *info);
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainenapr_status_t cache_write_entity_body(cache_handle_t *h, request_rec *r, apr_bucket_brigade *bb);
d22301419109ed4a38351715e6760011421dadecTimo Sirainenapr_status_t cache_read_entity_headers(cache_handle_t *h, request_rec *r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenapr_status_t cache_read_entity_body(cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen/* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainen * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE(type) __declspec(dllexport) type __stdcall
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllexport) type
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CACHE_DECLARE_DATA __declspec(dllexport)
6e1e9e341ffe21a69a23229c2b896d03066a071eTimo Sirainen#define CACHE_DECLARE(type) __declspec(dllimport) type __stdcall
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen#define CACHE_DECLARE_NONSTD(type) __declspec(dllimport) type
8da095519878426b012058e6f331a669f327f47fTimo Sirainen#define CACHE_DECLARE_DATA __declspec(dllimport)
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo SirainenAPR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, create_entity,
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen (cache_handle_t *h, request_rec *r, const char *type,
2e7e4804d8a88b10e00a3f9ec3726759ae0a6a13Timo SirainenAPR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, open_entity,
075086f56fdcc480b0e87aabde63128e30b49002Timo Sirainen (cache_handle_t *h, request_rec *r, const char *type,
d656ea23231ca1232b2dae327cea83bb44c6f6ffTimo Sirainen const char *urlkey))
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo SirainenAPR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, remove_url,
0d16525a729011f4fced989a3da74d755ea49e6dTimo Sirainen#endif /*MOD_CACHE_H*/