Apache2
mod_cache.h
Go to the documentation of this file.
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 
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 {
75  int status;
76  /* cached cache-control */
78 };
79 
80 /* cache handle information */
81 typedef struct cache_object cache_object_t;
82 struct cache_object {
83  const char *key;
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 {
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);
103  apr_bucket_brigade *out);
104  apr_status_t (*recall_headers) (cache_handle_t *h, request_rec *r);
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  apr_status_t (*invalidate_entity)(cache_handle_t *h, request_rec *r);
114 
115 typedef enum {
121 
122 #define AP_CACHE_HIT_ENV "cache-hit"
123 #define AP_CACHE_REVALIDATE_ENV "cache-revalidate"
124 #define AP_CACHE_MISS_ENV "cache-miss"
125 #define AP_CACHE_INVALIDATE_ENV "cache-invalidate"
126 #define AP_CACHE_STATUS_ENV "cache-status"
127 
128 
129 /* cache_util.c */
130 /* do a HTTP/1.1 age calculation */
132  apr_time_t now);
133 
137  int dirlength,
138  const char *name);
139 CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
140 
141 /* Create a new table consisting of those elements from an
142  * headers table that are allowed to be stored in a cache.
143  */
145  apr_table_t *t,
146  server_rec *s);
147 
148 /* Create a new table consisting of those elements from an input
149  * headers table that are allowed to be stored in a cache.
150  */
152 
153 /* Create a new table consisting of those elements from an output
154  * headers table that are allowed to be stored in a cache;
155  * ensure there is a content type and capture any errors.
156  */
158 
164 int ap_cache_control(request_rec *r, cache_control_t *cc, const char *cc_header,
165  const char *pragma_header, apr_table_t *headers);
166 
167 
168 /* hooks */
169 
182 APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, cache_status, (cache_handle_t *h,
184  const char *reason))
185 
188  (request_rec *r, apr_pool_t*p, const char **key));
189 
190 
191 #endif /*MOD_CACHE_H*/
APR-UTIL date routines.
Apache hook functions.
APR-UTIL registration of functions exported by modules.
Common Cache structs.
#define APR_DECLARE_EXTERNAL_HOOK(ns, link, ret, name, args)
Definition: apr_hooks.h:118
#define APR_DECLARE_OPTIONAL_FN(ret, name, args)
Definition: apr_optional.h:50
char * ap_cache_generate_name(apr_pool_t *p, int dirlevels, int dirlength, const char *name)
int ap_cache_control(request_rec *r, cache_control_t *cc, const char *cc_header, const char *pragma_header, apr_table_t *headers)
const char * ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str)
ap_cache_status_e
Definition: mod_cache.h:115
apr_table_t * ap_cache_cacheable_headers_out(request_rec *r)
apr_time_t ap_cache_hex2usec(const char *x)
apr_status_t ap_cache_generate_key(request_rec *r, apr_pool_t *p, const char **key)
#define CACHE_DECLARE(type)
Definition: mod_cache.h:40
void ap_cache_usec2hex(apr_time_t j, char *y)
apr_table_t * ap_cache_cacheable_headers_in(request_rec *r)
apr_time_t ap_cache_current_age(cache_info *info, const apr_time_t age_value, apr_time_t now)
apr_table_t * ap_cache_cacheable_headers(apr_pool_t *pool, apr_table_t *t, server_rec *s)
@ AP_CACHE_REVALIDATE
Definition: mod_cache.h:117
@ AP_CACHE_INVALIDATE
Definition: mod_cache.h:119
@ AP_CACHE_HIT
Definition: mod_cache.h:116
@ AP_CACHE_MISS
Definition: mod_cache.h:118
request_rec * r
Definition: mod_dav.h:518
dav_buffer const char * str
Definition: mod_dav.h:465
const dav_liveprop_group const dav_liveprop_spec ** info
Definition: mod_dav.h:1055
int status
Definition: mod_dav.h:141
apr_bucket_brigade * bb
Definition: mod_dav.h:555
const char * s
Definition: mod_dav.h:1327
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:557
const char * name
Definition: mod_dav.h:805
apr_table_t * headers
Definition: mod_proxy.h:1484
int
Definition: mod_proxy.h:674
int apr_status_t
Definition: apr_errno.h:44
off_t apr_off_t
Definition: apr.h:396
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
apr_int64_t apr_time_t
Definition: apr_time.h:45
HTTP Daemon routines.
Definition: apr_buckets.h:263
Definition: cache_common.h:30
Definition: mod_cache.h:91
apr_table_t * req_hdrs
Definition: mod_cache.h:93
apr_table_t * resp_hdrs
Definition: mod_cache.h:94
cache_object_t * cache_obj
Definition: mod_cache.h:92
Definition: mod_cache.h:59
apr_time_t date
Definition: mod_cache.h:64
int status
Definition: mod_cache.h:75
apr_time_t expire
Definition: mod_cache.h:66
apr_time_t request_time
Definition: mod_cache.h:68
apr_time_t response_time
Definition: mod_cache.h:70
cache_control_t control
Definition: mod_cache.h:77
Definition: mod_cache.h:82
const char * key
Definition: mod_cache.h:83
cache_object_t * next
Definition: mod_cache.h:84
cache_info info
Definition: mod_cache.h:85
void * vobj
Definition: mod_cache.h:87
Definition: mod_cache.h:99
A structure that represents the current request.
Definition: httpd.h:856
A structure to store information for each virtual server.
Definition: httpd.h:1382
apr_pool_t * p