cache_storage.c revision a2617cfd96f4e1b0cf1a8861ea980dfb28ffcbd5
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering/* Licensed to the Apache Software Foundation (ASF) under one or more
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * contributor license agreements. See the NOTICE file distributed with
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * this work for additional information regarding copyright ownership.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * The ASF licenses this file to You under the Apache License, Version 2.0
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * (the "License"); you may not use this file except in compliance with
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * the License. You may obtain a copy of the License at
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * http://www.apache.org/licenses/LICENSE-2.0
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * Unless required by applicable law or agreed to in writing, software
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * distributed under the License is distributed on an "AS IS" BASIS,
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * See the License for the specific language governing permissions and
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * limitations under the License.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringextern APR_OPTIONAL_FN_TYPE(ap_cache_generate_key) *cache_generate_key;
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringextern module AP_MODULE_DECLARE_DATA cache_module;
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering/* -------------------------------------------------------------- */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * delete all URL entities from the cache
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringint cache_remove_url(cache_request_rec *cache, request_rec *r)
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* Remove the stale cache entry if present. If not, we're
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * being called from outside of a request; remove the
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * non-stale handle.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering h = cache->stale_handle ? cache->stale_handle : cache->handle;
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00691)
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering "cache: Removing url %s from the cache", h->cache_obj->key);
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* for each specified cache type, delete the URL */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * create a new URL entity in the cache
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * It is possible to store more than once entity per URL. This
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * function will always create a new entity, regardless of whether
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * other entities already exist for the same URL.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * The size of the entity is provided so that a cache module can
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * decide whether or not it wants to cache this particular entity.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * If the size is unknown, a size of -1 should be set.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringint cache_create_entity(cache_request_rec *cache, request_rec *r,
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering cache_handle_t *h = apr_pcalloc(r->pool, sizeof(cache_handle_t));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* This should never happen */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r, APLOGNO(00692)
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering "cache: No cache request information available for key"
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering " generation");
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering rv = cache_generate_key(r, r->pool, &cache->key);
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* for each specified cache type, delete the URL */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering switch (rv = list->provider->create_entity(h, r, cache->key, size, in)) {
return OK;
case DECLINED: {
return rv;
return DECLINED;
if (revalidation) {
ap_set_content_type(r, v);
cache_handle_t *h;
if (!cache) {
return DECLINED;
return DECLINED;
return DECLINED;
while (list) {
case OK: {
int mismatch = 0;
while (vary) {
if (mismatch) {
r->headers_in);
if (!mismatch) {
APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r, APLOGNO(00695) "Cached response for %s isn't fresh. Adding "
if (etag) {
if (lastmod) {
lastmod);
return DECLINED;
return OK;
case DECLINED: {
return rv;
return HTTP_GATEWAY_TIME_OUT;
return DECLINED;
const char *path;
char *querystring;
if (*key) {
return APR_SUCCESS;
&cache_module);
if (!hostname) {
* scheme for this request. As r->parsed_uri.scheme is not set if this
char **identifier;
int len;
char *param;
if (querystring) {
char *complete;
if (param) {
param++;
if (param) {
char *amp;
NULL);
if (*querystring) {
NULL);
APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r, APLOGNO(00698) "cache: Key for entity %s?%s is %s", uri, parsed_uri->query, *key);
return APR_SUCCESS;
const char **key)
cache_handle_t *h;
if (!cache) {
APLOG_MARK, APLOG_ERR, APR_EGENERAL, r, APLOGNO(00697) "cache: No cache request information available for key"
return DECLINED;
return DECLINED;
if (location) {
|| APR_SUCCESS
if (content_location) {
if (APR_SUCCESS
|| APR_SUCCESS
while (list) {
APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(02468) "cache: Attempted to invalidate cached entity with key: %s", cache->key);
if (location_key) {
APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(02469) "cache: Attempted to invalidate cached entity with key: %s", location_key);
if (content_location_key) {
APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(02470) "cache: Attempted to invalidate cached entity with key: %s", content_location_key);
return status;