]> granicus.if.org Git - apache/blob - modules/cache/mod_disk_cache.h
mod_disk_cache: Do away with the write-to-file-then-move-in-place
[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 /*
21  * include for mod_disk_cache: Disk Based HTTP 1.1 Cache.
22  */
23
24 #define VARY_FORMAT_VERSION 3
25 #define DISK_FORMAT_VERSION_OLD 4
26 #define DISK_FORMAT_VERSION 5
27
28 #define CACHE_HEADER_SUFFIX ".header"
29 #define CACHE_DATA_SUFFIX   ".data"
30 #define CACHE_VDIR_SUFFIX   ".vary"
31
32 #define CACHE_BUF_SIZE 65536
33
34 /* How long to sleep before retrying while looping */
35 #define CACHE_LOOP_SLEEP 200000
36
37
38 #define AP_TEMPFILE_PREFIX "/"
39 #define AP_TEMPFILE_BASE   "aptmp"
40 #define AP_TEMPFILE_SUFFIX "XXXXXX"
41 #define AP_TEMPFILE_BASELEN strlen(AP_TEMPFILE_BASE)
42 #define AP_TEMPFILE_NAMELEN strlen(AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX)
43 #define AP_TEMPFILE AP_TEMPFILE_PREFIX AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX
44
45 /* Indicates the format of the header struct stored on-disk. */
46 typedef apr_uint32_t disk_cache_format_t;
47
48 typedef struct {
49     /* The HTTP status code returned for this response.  */
50     int status;
51     /* The size of the entity name that follows. */
52     apr_size_t name_len;
53     /* The number of times we've cached this entity. */
54     apr_size_t entity_version;
55     /* Miscellaneous time values. */
56     apr_time_t date;
57     apr_time_t expire;
58     apr_time_t request_time;
59     apr_time_t response_time;
60     /* The body size forced to 64bit to not break when people go from non-LFS
61      * to LFS builds */
62     apr_int64_t file_size;
63 } disk_cache_info_t;
64
65 /*
66  * disk_cache_object_t
67  * Pointed to by cache_object_t::vobj
68  */
69 typedef struct disk_cache_object {
70     const char *root;        /* the location of the cache directory */
71     apr_size_t root_len;
72     char *tempfile;    /* temp file tohold the content */
73     const char *prefix;
74     const char *datafile;    /* name of file where the data will go */
75     const char *hdrsfile;    /* name of file where the hdrs will go */
76     const char *hashfile;    /* Computed hash key for this URI */
77     const char *name;   /* Requested URI without vary bits - suitable for mortals. */
78     apr_file_t *fd;          /* data file */
79     apr_file_t *hfd;         /* headers file */
80     apr_file_t *tfd;         /* temporary file for data */
81     apr_off_t file_size;     /*  File size of the cached data file  */
82     apr_off_t initial_size;  /*  Initial file size reported by caller */
83     disk_cache_info_t disk_info; /* Header information. */
84
85     apr_interval_time_t updtimeout; /* Cache update timeout */
86
87     int skipstore;           /* Set if we should skip storing stuff */
88 } disk_cache_object_t;
89
90
91 /*
92  * mod_disk_cache configuration
93  */
94 /* TODO: Make defaults OS specific */
95 #define CACHEFILE_LEN 20        /* must be less than HASH_LEN/2 */
96 #define DEFAULT_DIRLEVELS 3
97 #define DEFAULT_DIRLENGTH 2
98 #define DEFAULT_MIN_FILE_SIZE 1
99 #define DEFAULT_MAX_FILE_SIZE 1000000
100 #define DEFAULT_UPDATE_TIMEOUT apr_time_from_sec(10)
101
102 typedef struct {
103     const char* cache_root;
104     apr_size_t cache_root_len;
105     int dirlevels;               /* Number of levels of subdirectories */
106     int dirlength;               /* Length of subdirectory names */
107     apr_off_t minfs;             /* minimum file size for cached files */
108     apr_off_t maxfs;             /* maximum file size for cached files */
109     apr_interval_time_t updtimeout;   /* Cache update timeout */
110 } disk_cache_conf;
111
112 #define CACHE_ENODATA (APR_OS_START_USERERR+1)
113 #define CACHE_EDECLINED (APR_OS_START_USERERR+2)
114 #define CACHE_EEXIST (APR_OS_START_USERERR+3)
115
116
117 #endif /*MOD_DISK_CACHE_H*/