]> granicus.if.org Git - apache/blob - modules/cache/mod_disk_cache.h
Be compliant with RFC2616 14.46, revalidation failed is Warning 111, not
[apache] / modules / cache / mod_disk_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 #ifndef MOD_DISK_CACHE_H
18 #define MOD_DISK_CACHE_H
19
20 #include "mod_cache.h"
21 #include "apr_file_io.h"
22
23 /*
24  * include for mod_disk_cache: Disk Based HTTP 1.1 Cache.
25  */
26
27 #define VARY_FORMAT_VERSION 5
28 #define DISK_FORMAT_VERSION 6
29
30 #define CACHE_HEADER_SUFFIX ".header"
31 #define CACHE_DATA_SUFFIX   ".data"
32 #define CACHE_VDIR_SUFFIX   ".vary"
33
34 #define AP_TEMPFILE_PREFIX "/"
35 #define AP_TEMPFILE_BASE   "aptmp"
36 #define AP_TEMPFILE_SUFFIX "XXXXXX"
37 #define AP_TEMPFILE_BASELEN strlen(AP_TEMPFILE_BASE)
38 #define AP_TEMPFILE_NAMELEN strlen(AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX)
39 #define AP_TEMPFILE AP_TEMPFILE_PREFIX AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX
40
41 typedef struct {
42     /* Indicates the format of the header struct stored on-disk. */
43     apr_uint32_t format;
44     /* The HTTP status code returned for this response.  */
45     int status;
46     /* The size of the entity name that follows. */
47     apr_size_t name_len;
48     /* The number of times we've cached this entity. */
49     apr_size_t entity_version;
50     /* Miscellaneous time values. */
51     apr_time_t date;
52     apr_time_t expire;
53     apr_time_t request_time;
54     apr_time_t response_time;
55     /* The ident of the body file, so we can test the body matches the header */
56     apr_ino_t inode;
57     apr_dev_t device;
58     /* Does this cached request have a body? */
59     int has_body:1;
60     int header_only:1;
61     /* The parsed cache control header */
62     cache_control_t control;
63 } disk_cache_info_t;
64
65 typedef struct {
66     apr_pool_t *pool;
67     const char *file;
68     apr_file_t *fd;
69     char *tempfile;
70     apr_file_t *tempfd;
71 } disk_cache_file_t;
72
73 /*
74  * disk_cache_object_t
75  * Pointed to by cache_object_t::vobj
76  */
77 typedef struct disk_cache_object {
78     const char *root;            /* the location of the cache directory */
79     apr_size_t root_len;
80     const char *prefix;
81     disk_cache_file_t data;      /* data file structure */
82     disk_cache_file_t hdrs;      /* headers file structure */
83     disk_cache_file_t vary;      /* vary file structure */
84     const char *hashfile;        /* Computed hash key for this URI */
85     const char *name;            /* Requested URI without vary bits - suitable for mortals. */
86     const char *key;             /* On-disk prefix; URI with Vary bits (if present) */
87     apr_off_t file_size;         /*  File size of the cached data file  */
88     disk_cache_info_t disk_info; /* Header information. */
89     apr_bucket_brigade *bb;      /* Set aside brigade */
90     apr_table_t *headers_in;     /* Input headers to save */
91     apr_table_t *headers_out;    /* Output headers to save */
92     apr_off_t offset;            /* Max size to set aside */
93     apr_time_t timeout;          /* Max time to set aside */
94     int done:1;                  /* Is the attempt to cache complete? */
95 } disk_cache_object_t;
96
97
98 /*
99  * mod_disk_cache configuration
100  */
101 /* TODO: Make defaults OS specific */
102 #define CACHEFILE_LEN 20        /* must be less than HASH_LEN/2 */
103 #define DEFAULT_DIRLEVELS 2
104 #define DEFAULT_DIRLENGTH 2
105 #define DEFAULT_MIN_FILE_SIZE 1
106 #define DEFAULT_MAX_FILE_SIZE 1000000
107 #define DEFAULT_READSIZE 0
108 #define DEFAULT_READTIME 0
109
110 typedef struct {
111     const char* cache_root;
112     apr_size_t cache_root_len;
113     int dirlevels;               /* Number of levels of subdirectories */
114     int dirlength;               /* Length of subdirectory names */
115 } disk_cache_conf;
116
117 typedef struct {
118     apr_off_t minfs;             /* minimum file size for cached files */
119     apr_off_t maxfs;             /* maximum file size for cached files */
120     apr_off_t readsize;          /* maximum data to attempt to cache in one go */
121     apr_time_t readtime;         /* maximum time taken to cache in one go */
122     int minfs_set:1;
123     int maxfs_set:1;
124     int readsize_set:1;
125     int readtime_set:1;
126 } disk_cache_dir_conf;
127
128 #endif /*MOD_DISK_CACHE_H*/