]> granicus.if.org Git - apache/blob - modules/cache/mod_cache.h
* Make module compile by fixing some typos.
[apache] / modules / cache / mod_cache.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file mod_cache.h
19  * @brief Main include file for the Apache Transparent Cache
20  *
21  * @defgroup MOD_CACHE mod_cache
22  * @ingroup  APACHE_MODS
23  * @{
24  */
25
26 #ifndef MOD_CACHE_H
27 #define MOD_CACHE_H
28
29 #include "httpd.h"
30 #include "apr_date.h"
31 #include "apr_optional.h"
32 #include "apr_hooks.h"
33
34 #include "cache_common.h"
35
36 /* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and
37  * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
38  */
39 #if !defined(WIN32)
40 #define CACHE_DECLARE(type)            type
41 #define CACHE_DECLARE_NONSTD(type)     type
42 #define CACHE_DECLARE_DATA
43 #elif defined(CACHE_DECLARE_STATIC)
44 #define CACHE_DECLARE(type)            type __stdcall
45 #define CACHE_DECLARE_NONSTD(type)     type
46 #define CACHE_DECLARE_DATA
47 #elif defined(CACHE_DECLARE_EXPORT)
48 #define CACHE_DECLARE(type)            __declspec(dllexport) type __stdcall
49 #define CACHE_DECLARE_NONSTD(type)     __declspec(dllexport) type
50 #define CACHE_DECLARE_DATA             __declspec(dllexport)
51 #else
52 #define CACHE_DECLARE(type)            __declspec(dllimport) type __stdcall
53 #define CACHE_DECLARE_NONSTD(type)     __declspec(dllimport) type
54 #define CACHE_DECLARE_DATA             __declspec(dllimport)
55 #endif
56
57 /* cache info information */
58 typedef struct cache_info cache_info;
59 struct cache_info {
60     /**
61      * the original time corresponding to the 'Date:' header of the request
62      * served
63      */
64     apr_time_t date;
65     /** a time when the cached entity is due to expire */
66     apr_time_t expire;
67     /** r->request_time from the same request */
68     apr_time_t request_time;
69     /** apr_time_now() at the time the entity was actually cached */
70     apr_time_t response_time;
71     /**
72      * HTTP status code of the cached entity. Though not necessarily the
73      * status code finally issued to the request.
74      */
75     int status;
76     /* cached cache-control */
77     cache_control_t control;
78 };
79
80 /* cache handle information */
81 typedef struct cache_object cache_object_t;
82 struct cache_object {
83     const char *key;
84     cache_object_t *next;
85     cache_info info;
86     /* Opaque portion (specific to the implementation) of the cache object */
87     void *vobj;
88 };
89
90 typedef struct cache_handle cache_handle_t;
91 struct cache_handle {
92     cache_object_t *cache_obj;
93     apr_table_t *req_hdrs;        /* cached request headers */
94     apr_table_t *resp_hdrs;       /* cached response headers */
95 };
96
97 #define CACHE_PROVIDER_GROUP "cache"
98
99 typedef struct {
100     int (*remove_entity) (cache_handle_t *h);
101     apr_status_t (*store_headers)(cache_handle_t *h, request_rec *r, cache_info *i);
102     apr_status_t (*store_body)(cache_handle_t *h, request_rec *r, apr_bucket_brigade *in,
103                            apr_bucket_brigade *out);
104     apr_status_t (*recall_headers) (cache_handle_t *h, request_rec *r);
105     apr_status_t (*recall_body) (cache_handle_t *h, apr_pool_t *p, apr_bucket_brigade *bb);
106     int (*create_entity) (cache_handle_t *h, request_rec *r,
107                            const char *urlkey, apr_off_t len, apr_bucket_brigade *bb);
108     int (*open_entity) (cache_handle_t *h, request_rec *r,
109                            const char *urlkey);
110     int (*remove_url) (cache_handle_t *h, request_rec *r);
111     apr_status_t (*commit_entity)(cache_handle_t *h, request_rec *r);
112 } cache_provider;
113
114 typedef enum {
115     AP_CACHE_HIT,
116     AP_CACHE_REVALIDATE,
117     AP_CACHE_MISS
118 } ap_cache_status_e;
119
120 #define AP_CACHE_HIT_ENV "cache-hit"
121 #define AP_CACHE_REVALIDATE_ENV "cache-revalidate"
122 #define AP_CACHE_MISS_ENV "cache-miss"
123 #define AP_CACHE_STATUS_ENV "cache-status"
124
125
126 /* cache_util.c */
127 /* do a HTTP/1.1 age calculation */
128 CACHE_DECLARE(apr_time_t) ap_cache_current_age(cache_info *info, const apr_time_t age_value,
129                                                apr_time_t now);
130
131 CACHE_DECLARE(apr_time_t) ap_cache_hex2usec(const char *x);
132 CACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y);
133 CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels,
134                                              int dirlength,
135                                              const char *name);
136 CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list,
137                                     const char *key, char **val);
138 CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
139
140 /* Create a new table consisting of those elements from an
141  * headers table that are allowed to be stored in a cache.
142  */
143 CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers(apr_pool_t *pool,
144                                                         apr_table_t *t,
145                                                         server_rec *s);
146
147 /* Create a new table consisting of those elements from an input
148  * headers table that are allowed to be stored in a cache.
149  */
150 CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_in(request_rec *r);
151
152 /* Create a new table consisting of those elements from an output
153  * headers table that are allowed to be stored in a cache;
154  * ensure there is a content type and capture any errors.
155  */
156 CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_out(request_rec *r);
157
158 /**
159  * Parse the Cache-Control and Pragma headers in one go, marking
160  * which tokens appear within the header. Populate the structure
161  * passed in.
162  */
163 int ap_cache_control(request_rec *r, cache_control_t *cc, const char *cc_header,
164         const char *pragma_header, apr_table_t *headers);
165
166
167 /* hooks */
168
169 /**
170  * Cache status hook.
171  * This hook is called as soon as the cache has made a decision as to whether
172  * an entity should be served from cache (hit), should be served from cache
173  * after a successful validation (revalidate), or served from the backend
174  * and potentially cached (miss).
175  *
176  * A basic implementation of this hook exists in mod_cache which writes this
177  * information to the subprocess environment, and optionally to request
178  * headers. Further implementations may add hooks as appropriate to perform
179  * more advanced processing, or to store statistics about the cache behaviour.
180  */
181 APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, cache_status, (cache_handle_t *h,
182                 request_rec *r, apr_table_t *headers, ap_cache_status_e status,
183                 const char *reason))
184
185 APR_DECLARE_OPTIONAL_FN(apr_status_t,
186                         ap_cache_generate_key,
187                         (request_rec *r, apr_pool_t*p, const char **key));
188
189
190 #endif /*MOD_CACHE_H*/
191 /** @} */