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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef MOD_DISK_CACHE_H
18 #define MOD_DISK_CACHE_H
21 * include for mod_disk_cache: Disk Based HTTP 1.1 Cache.
24 #define VARY_FORMAT_VERSION 3
25 #define DISK_FORMAT_VERSION_OLD 4
26 #define DISK_FORMAT_VERSION 5
28 #define CACHE_HEADER_SUFFIX ".header"
29 #define CACHE_DATA_SUFFIX ".data"
30 #define CACHE_VDIR_SUFFIX ".vary"
32 #define CACHE_BUF_SIZE 65536
34 /* How long to sleep before retrying while looping */
35 #define CACHE_LOOP_SLEEP 200000
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
45 /* Indicates the format of the header struct stored on-disk. */
46 typedef apr_uint32_t disk_cache_format_t;
49 /* The HTTP status code returned for this response. */
51 /* The size of the entity name that follows. */
53 /* The number of times we've cached this entity. */
54 apr_size_t entity_version;
55 /* Miscellaneous time values. */
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
62 apr_int64_t file_size;
67 * Pointed to by cache_object_t::vobj
69 typedef struct disk_cache_object {
70 const char *root; /* the location of the cache directory */
72 char *tempfile; /* temp file tohold the content */
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. */
85 apr_interval_time_t updtimeout; /* Cache update timeout */
87 int skipstore; /* Set if we should skip storing stuff */
88 int store_body_called; /* Number of times store_body() has executed */
89 apr_bucket_brigade *tmpbb; /* Temporary bucket brigade. */
90 apr_status_t frv; /* Last known status of network write */
91 } disk_cache_object_t;
95 * mod_disk_cache configuration
97 /* TODO: Make defaults OS specific */
98 #define CACHEFILE_LEN 20 /* must be less than HASH_LEN/2 */
99 #define DEFAULT_DIRLEVELS 2
100 #define DEFAULT_DIRLENGTH 2
101 #define DEFAULT_MIN_FILE_SIZE 1
102 #define DEFAULT_MAX_FILE_SIZE 1000000
103 #define DEFAULT_UPDATE_TIMEOUT apr_time_from_sec(10)
106 const char* cache_root;
107 apr_size_t cache_root_len;
108 int dirlevels; /* Number of levels of subdirectories */
109 int dirlength; /* Length of subdirectory names */
110 apr_off_t minfs; /* minimum file size for cached files */
111 apr_off_t maxfs; /* maximum file size for cached files */
112 apr_interval_time_t updtimeout; /* Cache update timeout */
115 #define CACHE_ENODATA (APR_OS_START_USERERR+1)
116 #define CACHE_EDECLINED (APR_OS_START_USERERR+2)
117 #define CACHE_EEXIST (APR_OS_START_USERERR+3)
120 typedef struct diskcache_bucket_data diskcache_bucket_data;
121 struct diskcache_bucket_data {
122 /* Number of buckets using this memory */
123 apr_bucket_refcount refcount;
125 /* The pool into which any needed structures should
126 * be created while reading from this file bucket */
127 apr_pool_t *readpool;
128 /* Cache update timeout */
129 apr_interval_time_t updtimeout;
134 #endif /*MOD_DISK_CACHE_H*/