Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 */
82 struct cache_object {
83  const char *key;
86  /* Opaque portion (specific to the implementation) of the cache object */
87  void *vobj;
88 };
89 
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 
135 CACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y);
136 CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels,
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*/
192 
apr_table_t * ap_cache_cacheable_headers_in(request_rec *r)
#define CACHE_DECLARE(type)
Definition: mod_cache.h:40
cache_control_t control
Definition: mod_cache.h:77
apr_time_t ap_cache_current_age(cache_info *info, const apr_time_t age_value, apr_time_t now)
void ap_cache_usec2hex(apr_time_t j, char *y)
Definition: mod_cache.h:116
Definition: mod_cache.h:99
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:552
apr_time_t request_time
Definition: mod_cache.h:68
apr_status_t ap_cache_generate_key(request_rec *r, apr_pool_t *p, const char **key)
Definition: mod_cache.h:82
Definition: cache_common.h:30
char * ap_cache_generate_name(apr_pool_t *p, int dirlevels, int dirlength, const char *name)
Definition: apr_buckets.h:258
int ap_cache_control(request_rec *r, cache_control_t *cc, const char *cc_header, const char *pragma_header, apr_table_t *headers)
Definition: mod_cache.h:119
APR-UTIL registration of functions exported by modules.
apr_table_t * req_hdrs
Definition: mod_cache.h:93
apr_int64_t apr_time_t
Definition: apr_time.h:45
APR-UTIL date routines.
apr_bucket_brigade * bb
Definition: mod_dav.h:552
cache_object_t * cache_obj
Definition: mod_cache.h:92
HTTP Daemon routines.
Apache hook functions.
A structure to store information for each virtual server.
Definition: httpd.h:1310
int
Definition: mod_proxy.h:626
#define APR_DECLARE_EXTERNAL_HOOK(ns, link, ret, name, args)
Definition: apr_hooks.h:118
Definition: mod_cache.h:59
Common Cache structs.
apr_time_t date
Definition: mod_cache.h:64
cache_info info
Definition: mod_cache.h:85
apr_table_t * ap_cache_cacheable_headers(apr_pool_t *pool, apr_table_t *t, server_rec *s)
apr_table_t * resp_hdrs
Definition: mod_cache.h:94
Definition: mod_cache.h:117
apr_table_t * ap_cache_cacheable_headers_out(request_rec *r)
Definition: mod_cache.h:91
const dav_liveprop_group const dav_liveprop_spec ** info
Definition: mod_dav.h:966
apr_pool_t * p
const char * key
Definition: mod_cache.h:83
apr_time_t ap_cache_hex2usec(const char *x)
cache_object_t * next
Definition: mod_cache.h:84
Definition: mod_cache.h:118
apr_time_t response_time
Definition: mod_cache.h:70
A structure that represents the current request.
Definition: httpd.h:806
int status
Definition: mod_cache.h:75
dav_buffer const char * str
Definition: mod_dav.h:461
int status
Definition: mod_dav.h:141
const char * ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str)
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
const char * name
Definition: mod_dav.h:726
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44
ap_cache_status_e
Definition: mod_cache.h:115
request_rec * r
Definition: mod_dav.h:515
#define APR_DECLARE_OPTIONAL_FN(ret, name, args)
Definition: apr_optional.h:50
off_t apr_off_t
Definition: apr.h:377
void * vobj
Definition: mod_cache.h:87
apr_time_t expire
Definition: mod_cache.h:66