]> granicus.if.org Git - apache/blob - modules/cache/mod_disk_cache.h
mod_cache: Add a discrete commit_entity() provider function within the
[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 4
26
27 #define CACHE_HEADER_SUFFIX ".header"
28 #define CACHE_DATA_SUFFIX   ".data"
29 #define CACHE_VDIR_SUFFIX   ".vary"
30
31 #define AP_TEMPFILE_PREFIX "/"
32 #define AP_TEMPFILE_BASE   "aptmp"
33 #define AP_TEMPFILE_SUFFIX "XXXXXX"
34 #define AP_TEMPFILE_BASELEN strlen(AP_TEMPFILE_BASE)
35 #define AP_TEMPFILE_NAMELEN strlen(AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX)
36 #define AP_TEMPFILE AP_TEMPFILE_PREFIX AP_TEMPFILE_BASE AP_TEMPFILE_SUFFIX
37
38 typedef struct {
39     /* Indicates the format of the header struct stored on-disk. */
40     apr_uint32_t format;
41     /* The HTTP status code returned for this response.  */
42     int status;
43     /* The size of the entity name that follows. */
44     apr_size_t name_len;
45     /* The number of times we've cached this entity. */
46     apr_size_t entity_version;
47     /* Miscellaneous time values. */
48     apr_time_t date;
49     apr_time_t expire;
50     apr_time_t request_time;
51     apr_time_t response_time;
52 } disk_cache_info_t;
53
54 typedef struct {
55     apr_pool_t *pool;
56     const char *file;
57     apr_file_t *fd;
58     char *tempfile;
59     apr_file_t *tempfd;
60 } disk_cache_file_t;
61
62 /*
63  * disk_cache_object_t
64  * Pointed to by cache_object_t::vobj
65  */
66 typedef struct disk_cache_object {
67     const char *root;            /* the location of the cache directory */
68     apr_size_t root_len;
69     const char *prefix;
70     disk_cache_file_t data;      /* data file structure */
71     disk_cache_file_t hdrs;      /* headers file structure */
72     disk_cache_file_t vary;      /* vary file structure */
73     const char *hashfile;        /* Computed hash key for this URI */
74     const char *name;            /* Requested URI without vary bits - suitable for mortals. */
75     const char *key;             /* On-disk prefix; URI with Vary bits (if present) */
76     apr_off_t file_size;         /*  File size of the cached data file  */
77     disk_cache_info_t disk_info; /* Header information. */
78     apr_bucket_brigade *bb;      /* Set aside brigade */
79     apr_off_t offset;            /* Max size to set aside */
80     apr_time_t timeout;          /* Max time to set aside */
81     int done;                    /* Is the attempt to cache complete? */
82 } disk_cache_object_t;
83
84
85 /*
86  * mod_disk_cache configuration
87  */
88 /* TODO: Make defaults OS specific */
89 #define CACHEFILE_LEN 20        /* must be less than HASH_LEN/2 */
90 #define DEFAULT_DIRLEVELS 2
91 #define DEFAULT_DIRLENGTH 2
92 #define DEFAULT_MIN_FILE_SIZE 1
93 #define DEFAULT_MAX_FILE_SIZE 1000000
94 #define DEFAULT_READSIZE 0
95 #define DEFAULT_READTIME 0
96
97 typedef struct {
98     const char* cache_root;
99     apr_size_t cache_root_len;
100     int dirlevels;               /* Number of levels of subdirectories */
101     int dirlength;               /* Length of subdirectory names */
102     apr_off_t minfs;             /* minimum file size for cached files */
103     apr_off_t maxfs;             /* maximum file size for cached files */
104 } disk_cache_conf;
105
106 typedef struct {
107     apr_off_t readsize;          /* maximum data to attempt to cache in one go */
108     apr_time_t readtime;         /* maximum time taken to cache in one go */
109     int readsize_set;
110     int readtime_set;
111 } disk_cache_dir_conf;
112
113 #endif /*MOD_DISK_CACHE_H*/