* decide whether or not it wants to cache this particular entity.
* If the size is unknown, a size of -1 should be set.
*/
-int cache_create_entity(request_rec *r, apr_off_t size, apr_bucket_brigade *in)
+int cache_create_entity(cache_request_rec *cache, request_rec *r,
+ apr_off_t size, apr_bucket_brigade *in)
{
cache_provider_list *list;
cache_handle_t *h = apr_pcalloc(r->pool, sizeof(cache_handle_t));
char *key;
apr_status_t rv;
- cache_request_rec *cache;
- void *data;
- apr_pool_userdata_get(&data, MOD_CACHE_REQUEST_REC, r->pool);
- cache = data;
-
- rv = cache_generate_key(r, r->pool, &key);
+ rv = cache_generate_key(cache, r, r->pool, &key);
if (rv != APR_SUCCESS) {
return rv;
}
* This function returns OK if successful, DECLINED if no
* cached entity fits the bill.
*/
-int cache_select(request_rec *r)
+int cache_select(cache_request_rec *cache, request_rec *r)
{
cache_provider_list *list;
apr_status_t rv;
cache_handle_t *h;
char *key;
- cache_request_rec *cache;
- void *data;
-
- apr_pool_userdata_get(&data, MOD_CACHE_REQUEST_REC, r->pool);
- cache = data;
- rv = cache_generate_key(r, r->pool, &key);
+ rv = cache_generate_key(cache, r, r->pool, &key);
if (rv != APR_SUCCESS) {
return rv;
}
cache->provider_name = list->provider_name;
/* Is our cached response fresh enough? */
- fresh = ap_cache_check_freshness(h, r);
+ fresh = ap_cache_check_freshness(h, cache, r);
if (!fresh) {
const char *etag, *lastmod;
return DECLINED;
}
-apr_status_t cache_generate_key_default(request_rec *r, apr_pool_t* p,
- char**key)
+apr_status_t cache_generate_key_default(cache_request_rec *cache, request_rec *r,
+ apr_pool_t* p, char **key)
{
cache_server_conf *conf;
- cache_request_rec *cache;
char *port_str, *hn, *lcs;
const char *hostname, *scheme;
int i;
char *path, *querystring;
- void *data;
- apr_pool_userdata_get(&data, MOD_CACHE_REQUEST_REC, r->pool);
- cache = data;
if (!cache) {
/* This should never happen */
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
/**
* cache_storage.c
*/
-#define MOD_CACHE_REQUEST_REC "mod_cache_request_rec"
int cache_remove_url(cache_request_rec *cache, apr_pool_t *p);
-int cache_create_entity(request_rec *r, apr_off_t size, apr_bucket_brigade *in);
-int cache_select(request_rec *r);
-apr_status_t cache_generate_key_default( request_rec *r, apr_pool_t*p, char**key );
+int cache_create_entity(cache_request_rec *cache, request_rec *r,
+ apr_off_t size, apr_bucket_brigade *in);
+int cache_select(cache_request_rec *cache, request_rec *r);
+apr_status_t cache_generate_key_default(cache_request_rec *cache, request_rec *r,
+ apr_pool_t* p, char **key);
#ifdef __cplusplus
}
* the backend.
*/
CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
- request_rec *r, char *key) {
+ cache_request_rec *cache, request_rec *r, char *key)
+{
apr_status_t status;
const char *lockname;
const char *path;
/* create the key if it doesn't exist */
if (!key) {
- cache_generate_key(r, r->pool, &key);
+ cache_generate_key(cache, r, r->pool, &key);
}
/* create a hashed filename from the key, and save it for later */
* removed if the bucket brigade contains an EOS bucket.
*/
CACHE_DECLARE(apr_status_t) ap_cache_remove_lock(cache_server_conf *conf,
- request_rec *r, char *key, apr_bucket_brigade *bb) {
+ cache_request_rec *cache, request_rec *r, char *key,
+ apr_bucket_brigade *bb)
+{
void *dummy;
const char *lockname;
/* create the key if it doesn't exist */
if (!key) {
- cache_generate_key(r, r->pool, &key);
+ cache_generate_key(cache, r, r->pool, &key);
}
/* create a hashed filename from the key, and save it for later */
CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h,
+ cache_request_rec *cache,
request_rec *r)
{
apr_status_t status;
* A lock that exceeds a maximum age will be deleted, and another
* request gets to make a new lock and try again.
*/
- status = ap_cache_try_lock(conf, r, (char *)h->cache_obj->key);
+ status = ap_cache_try_lock(conf, cache, r, (char *)h->cache_obj->key);
if (APR_SUCCESS == status) {
/* we obtained a lock, follow the stale path */
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
cache->size = -1;
cache->out = apr_brigade_create(r->pool, r->connection->bucket_alloc);
- /* store away the per request config where the API can find it */
- apr_pool_userdata_setn(cache, MOD_CACHE_REQUEST_REC, NULL, r->pool);
-
/* save away the possible providers */
cache->providers = providers;
* add cache_out filter
* return OK
*/
- rv = cache_select(r);
+ rv = cache_select(cache, r);
if (rv != OK) {
if (rv == DECLINED) {
if (!lookup) {
* backend without any attempt to cache. this stops
* duplicated simultaneous attempts to cache an entity.
*/
- rv = ap_cache_try_lock(conf, r, NULL);
+ rv = ap_cache_try_lock(conf, cache, r, NULL);
if (APR_SUCCESS == rv) {
/*
cache->size = -1;
cache->out = apr_brigade_create(r->pool, r->connection->bucket_alloc);
- /* store away the per request config where the API can find it */
- apr_pool_userdata_setn(cache, MOD_CACHE_REQUEST_REC, NULL, r->pool);
-
/* save away the possible providers */
cache->providers = providers;
* add cache_out filter
* return OK
*/
- rv = cache_select(r);
+ rv = cache_select(cache, r);
if (rv != OK) {
if (rv == DECLINED) {
* backend without any attempt to cache. this stops
* duplicated simultaneous attempts to cache an entity.
*/
- rv = ap_cache_try_lock(conf, r, NULL);
+ rv = ap_cache_try_lock(conf, cache, r, NULL);
if (APR_SUCCESS == rv) {
/*
ap_remove_output_filter(f);
/* give someone else the chance to cache the file */
- ap_cache_remove_lock(conf, f->r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, f->r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, NULL);
/* give up trying to cache, just step out the way */
}
/* conditionally remove the lock as soon as we see the eos bucket */
- ap_cache_remove_lock(conf, f->r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, f->r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, cache->out);
if (APR_BRIGADE_EMPTY(cache->out)) {
ap_remove_output_filter(f);
/* give someone else the chance to cache the file */
- ap_cache_remove_lock(conf, f->r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, f->r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, NULL);
return ap_pass_brigade(f->next, in);
ap_remove_output_filter(f);
/* remove the lock file unconditionally */
- ap_cache_remove_lock(conf, r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, NULL);
/* ship the data up the stack */
/* no cache handle, create a new entity only for non-HEAD requests */
if (!cache->handle && !r->header_only) {
- rv = cache_create_entity(r, size, in);
+ rv = cache_create_entity(cache, r, size, in);
info = apr_pcalloc(r->pool, sizeof(cache_info));
/* We only set info->status upon the initial creation. */
info->status = r->status;
if (rv != OK) {
/* Caching layer declined the opportunity to cache the response */
ap_remove_output_filter(f);
- ap_cache_remove_lock(conf, r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, NULL);
return ap_pass_brigade(f->next, in);
}
}
/* let someone else attempt to cache */
- ap_cache_remove_lock(conf, r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, NULL);
return ap_pass_brigade(f->next, bb);
"cache: store_headers failed");
ap_remove_output_filter(f);
- ap_cache_remove_lock(conf, r, cache->handle ?
+ ap_cache_remove_lock(conf, cache, r, cache->handle ?
(char *)cache->handle->cache_obj->key : NULL, NULL);
return ap_pass_brigade(f->next, in);
}
cache_provider_list *providers; /* possible cache providers */
const cache_provider *provider; /* current cache provider */
const char *provider_name; /* current cache provider name */
- int fresh; /* is the entitey fresh? */
+ int fresh; /* is the entity fresh? */
cache_handle_t *handle; /* current cache handle */
cache_handle_t *stale_handle; /* stale cache handle */
apr_table_t *stale_headers; /* original request headers. */
* @param r request_rec
* @return 0 ==> cache object is stale, 1 ==> cache object is fresh
*/
-CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, request_rec *r);
+CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, cache_request_rec *cache,
+ request_rec *r);
/**
* Check the whether the request allows a cached object to be served as per RFC2616
* the backend.
*/
CACHE_DECLARE(apr_status_t) ap_cache_try_lock(cache_server_conf *conf,
- request_rec *r, char *key);
+ cache_request_rec *cache, request_rec *r, char *key);
/**
* Remove the cache lock, if present.
* removed if the bucket brigade contains an EOS bucket.
*/
CACHE_DECLARE(apr_status_t) ap_cache_remove_lock(cache_server_conf *conf,
- request_rec *r, char *key, apr_bucket_brigade *bb);
+ cache_request_rec *cache, request_rec *r, char *key,
+ apr_bucket_brigade *bb);
/**
* Merge in cached headers into the response
APR_DECLARE_OPTIONAL_FN(apr_status_t,
ap_cache_generate_key,
- (request_rec *r, apr_pool_t*p, char**key ));
+ (cache_request_rec *cache, request_rec *r,
+ apr_pool_t*p, char **key));
#endif /*MOD_CACHE_H*/