Blame modules/cache/mod_cache.h

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * @file mod_cache.h
Packit 90a5c9
 * @brief Main include file for the Apache Transparent Cache
Packit 90a5c9
 *
Packit 90a5c9
 * @defgroup MOD_CACHE mod_cache
Packit 90a5c9
 * @ingroup  APACHE_MODS
Packit 90a5c9
 * @{
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#ifndef MOD_CACHE_H
Packit 90a5c9
#define MOD_CACHE_H
Packit 90a5c9
Packit 90a5c9
#include "httpd.h"
Packit 90a5c9
#include "apr_date.h"
Packit 90a5c9
#include "apr_optional.h"
Packit 90a5c9
#include "apr_hooks.h"
Packit 90a5c9
Packit 90a5c9
#include "cache_common.h"
Packit 90a5c9
Packit 90a5c9
/* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and
Packit 90a5c9
 * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
Packit 90a5c9
 */
Packit 90a5c9
#if !defined(WIN32)
Packit 90a5c9
#define CACHE_DECLARE(type)            type
Packit 90a5c9
#define CACHE_DECLARE_NONSTD(type)     type
Packit 90a5c9
#define CACHE_DECLARE_DATA
Packit 90a5c9
#elif defined(CACHE_DECLARE_STATIC)
Packit 90a5c9
#define CACHE_DECLARE(type)            type __stdcall
Packit 90a5c9
#define CACHE_DECLARE_NONSTD(type)     type
Packit 90a5c9
#define CACHE_DECLARE_DATA
Packit 90a5c9
#elif defined(CACHE_DECLARE_EXPORT)
Packit 90a5c9
#define CACHE_DECLARE(type)            __declspec(dllexport) type __stdcall
Packit 90a5c9
#define CACHE_DECLARE_NONSTD(type)     __declspec(dllexport) type
Packit 90a5c9
#define CACHE_DECLARE_DATA             __declspec(dllexport)
Packit 90a5c9
#else
Packit 90a5c9
#define CACHE_DECLARE(type)            __declspec(dllimport) type __stdcall
Packit 90a5c9
#define CACHE_DECLARE_NONSTD(type)     __declspec(dllimport) type
Packit 90a5c9
#define CACHE_DECLARE_DATA             __declspec(dllimport)
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/* cache info information */
Packit 90a5c9
typedef struct cache_info cache_info;
Packit 90a5c9
struct cache_info {
Packit 90a5c9
    /**
Packit 90a5c9
     * the original time corresponding to the 'Date:' header of the request
Packit 90a5c9
     * served
Packit 90a5c9
     */
Packit 90a5c9
    apr_time_t date;
Packit 90a5c9
    /** a time when the cached entity is due to expire */
Packit 90a5c9
    apr_time_t expire;
Packit 90a5c9
    /** r->request_time from the same request */
Packit 90a5c9
    apr_time_t request_time;
Packit 90a5c9
    /** apr_time_now() at the time the entity was actually cached */
Packit 90a5c9
    apr_time_t response_time;
Packit 90a5c9
    /**
Packit 90a5c9
     * HTTP status code of the cached entity. Though not necessarily the
Packit 90a5c9
     * status code finally issued to the request.
Packit 90a5c9
     */
Packit 90a5c9
    int status;
Packit 90a5c9
    /* cached cache-control */
Packit 90a5c9
    cache_control_t control;
Packit 90a5c9
};
Packit 90a5c9
Packit 90a5c9
/* cache handle information */
Packit 90a5c9
typedef struct cache_object cache_object_t;
Packit 90a5c9
struct cache_object {
Packit 90a5c9
    const char *key;
Packit 90a5c9
    cache_object_t *next;
Packit 90a5c9
    cache_info info;
Packit 90a5c9
    /* Opaque portion (specific to the implementation) of the cache object */
Packit 90a5c9
    void *vobj;
Packit 90a5c9
};
Packit 90a5c9
Packit 90a5c9
typedef struct cache_handle cache_handle_t;
Packit 90a5c9
struct cache_handle {
Packit 90a5c9
    cache_object_t *cache_obj;
Packit 90a5c9
    apr_table_t *req_hdrs;        /* cached request headers */
Packit 90a5c9
    apr_table_t *resp_hdrs;       /* cached response headers */
Packit 90a5c9
};
Packit 90a5c9
Packit 90a5c9
#define CACHE_PROVIDER_GROUP "cache"
Packit 90a5c9
Packit 90a5c9
typedef struct {
Packit 90a5c9
    int (*remove_entity) (cache_handle_t *h);
Packit 90a5c9
    apr_status_t (*store_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
Packit 90a5c9
    apr_status_t (*store_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *in,
Packit 90a5c9
                           apr_bucket_brigade *out);
Packit 90a5c9
    apr_status_t (*recall_headers) (cache_handle_t *h, request_rec *r);
Packit 90a5c9
    apr_status_t (*recall_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
Packit 90a5c9
    int (*create_entity) (cache_handle_t *h, request_rec *r,
Packit 90a5c9
                           const char *urlkey, apr_off_t len, apr_bucket_brigade *bb);
Packit 90a5c9
    int (*open_entity) (cache_handle_t *h, request_rec *r,
Packit 90a5c9
                           const char *urlkey);
Packit 90a5c9
    int (*remove_url) (cache_handle_t *h, request_rec *r);
Packit 90a5c9
    apr_status_t (*commit_entity)(cache_handle_t *h, request_rec *r);
Packit 90a5c9
    apr_status_t (*invalidate_entity)(cache_handle_t *h, request_rec *r);
Packit 90a5c9
} cache_provider;
Packit 90a5c9
Packit 90a5c9
typedef enum {
Packit 90a5c9
    AP_CACHE_HIT,
Packit 90a5c9
    AP_CACHE_REVALIDATE,
Packit 90a5c9
    AP_CACHE_MISS,
Packit 90a5c9
    AP_CACHE_INVALIDATE
Packit 90a5c9
} ap_cache_status_e;
Packit 90a5c9
Packit 90a5c9
#define AP_CACHE_HIT_ENV "cache-hit"
Packit 90a5c9
#define AP_CACHE_REVALIDATE_ENV "cache-revalidate"
Packit 90a5c9
#define AP_CACHE_MISS_ENV "cache-miss"
Packit 90a5c9
#define AP_CACHE_INVALIDATE_ENV "cache-invalidate"
Packit 90a5c9
#define AP_CACHE_STATUS_ENV "cache-status"
Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
/* cache_util.c */
Packit 90a5c9
/* do a HTTP/1.1 age calculation */
Packit 90a5c9
CACHE_DECLARE(apr_time_t) ap_cache_current_age(cache_info *info, const apr_time_t age_value,
Packit 90a5c9
                                               apr_time_t now);
Packit 90a5c9
Packit 90a5c9
CACHE_DECLARE(apr_time_t) ap_cache_hex2usec(const char *x);
Packit 90a5c9
CACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y);
Packit 90a5c9
CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels,
Packit 90a5c9
                                             int dirlength,
Packit 90a5c9
                                             const char *name);
Packit 90a5c9
CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
Packit 90a5c9
Packit 90a5c9
/* Create a new table consisting of those elements from an
Packit 90a5c9
 * headers table that are allowed to be stored in a cache.
Packit 90a5c9
 */
Packit 90a5c9
CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers(apr_pool_t *pool,
Packit 90a5c9
                                                        apr_table_t *t,
Packit 90a5c9
                                                        server_rec *s);
Packit 90a5c9
Packit 90a5c9
/* Create a new table consisting of those elements from an input
Packit 90a5c9
 * headers table that are allowed to be stored in a cache.
Packit 90a5c9
 */
Packit 90a5c9
CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_in(request_rec *r);
Packit 90a5c9
Packit 90a5c9
/* Create a new table consisting of those elements from an output
Packit 90a5c9
 * headers table that are allowed to be stored in a cache;
Packit 90a5c9
 * ensure there is a content type and capture any errors.
Packit 90a5c9
 */
Packit 90a5c9
CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_out(request_rec *r);
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Parse the Cache-Control and Pragma headers in one go, marking
Packit 90a5c9
 * which tokens appear within the header. Populate the structure
Packit 90a5c9
 * passed in.
Packit 90a5c9
 */
Packit 90a5c9
int ap_cache_control(request_rec *r, cache_control_t *cc, const char *cc_header,
Packit 90a5c9
        const char *pragma_header, apr_table_t *headers);
Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
/* hooks */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Cache status hook.
Packit 90a5c9
 * This hook is called as soon as the cache has made a decision as to whether
Packit 90a5c9
 * an entity should be served from cache (hit), should be served from cache
Packit 90a5c9
 * after a successful validation (revalidate), or served from the backend
Packit 90a5c9
 * and potentially cached (miss).
Packit 90a5c9
 *
Packit 90a5c9
 * A basic implementation of this hook exists in mod_cache which writes this
Packit 90a5c9
 * information to the subprocess environment, and optionally to request
Packit 90a5c9
 * headers. Further implementations may add hooks as appropriate to perform
Packit 90a5c9
 * more advanced processing, or to store statistics about the cache behaviour.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, cache_status, (cache_handle_t *h,
Packit 90a5c9
                request_rec *r, apr_table_t *headers, ap_cache_status_e status,
Packit 90a5c9
                const char *reason))
Packit 90a5c9
Packit 90a5c9
APR_DECLARE_OPTIONAL_FN(apr_status_t,
Packit 90a5c9
                        ap_cache_generate_key,
Packit 90a5c9
                        (request_rec *r, apr_pool_t*p, const char **key));
Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
#endif /*MOD_CACHE_H*/
Packit 90a5c9
/** @} */