]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_file_cache.xml
Fix a number of typos and misspellings. Reported by Ville Skytta.
[apache] / docs / manual / mod / mod_file_cache.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <modulesynopsis metafile="mod_file_cache.xml.meta">
24
25 <name>mod_file_cache</name>
26 <description>Caches a static list of files in memory</description>
27 <status>Experimental</status>
28 <sourcefile>mod_file_cache.c</sourcefile>
29 <identifier>file_cache_module</identifier>
30
31 <summary>
32
33     <note type="warning">
34       This module should be used with care. You can easily create a broken
35       site using <module>mod_file_cache</module>, so read this document
36       carefully.
37     </note>
38
39     <p><em>Caching</em> frequently requested files that change very
40     infrequently is a technique for reducing server load.
41     <module>mod_file_cache</module> provides two techniques for caching
42     frequently requested <em>static</em> files. Through configuration
43     directives, you can direct <module>mod_file_cache</module> to either
44     open then <code>mmap()</code> a file, or to pre-open a file and save
45     the file's open <em>file handle</em>. Both techniques reduce server
46     load when processing requests for these files by doing part of the work
47     (specifically, the file I/O) for serving the file when the
48     server is started rather than during each request.</p>
49
50     <p>Notice: You cannot use this for speeding up CGI programs or
51     other files which are served by special content handlers. It
52     can only be used for regular files which are usually served by
53     the Apache core content handler.</p>
54
55     <p>This module is an extension of and borrows heavily from the
56     <code>mod_mmap_static</code> module in Apache 1.3.</p>
57 </summary>
58
59 <section id="using"><title>Using mod_file_cache</title>
60
61     <p><module>mod_file_cache</module> caches a list of statically
62     configured files via <directive module="mod_file_cache"
63     >MMapFile</directive> or <directive module="mod_file_cache"
64     >CacheFile</directive> directives in the main server configuration.</p>
65
66     <p>Not all platforms support both directives. You will receive an error
67     message in the server error log if you attempt to use an
68     unsupported directive. If given an unsupported directive, the
69     server will start but the file will not be cached. On platforms
70     that support both directives, you should experiment with both to
71     see which works best for you.</p>
72
73     <section><title>MMapFile Directive</title>
74
75       <p>The <directive module="mod_file_cache">MMapFile</directive>
76       directive of <module>mod_file_cache</module> maps a list of
77       statically configured files into memory through the system call
78       <code>mmap()</code>. This system call is available on most modern
79       Unix derivatives, but not on all. There are sometimes system-specific
80       limits on the size and number of files that can be
81       <code>mmap()</code>ed, experimentation is probably the easiest way
82       to find out.</p>
83
84       <p>This <code>mmap()</code>ing is done once at server start or
85       restart, only. So whenever one of the mapped files changes on the
86       filesystem you <em>have</em> to restart the server (see the <a
87       href="../stopping.html">Stopping and Restarting</a> documentation).
88       To reiterate that point: if the files are modified <em>in place</em>
89       without restarting the server you may end up serving requests that
90       are completely bogus. You should update files by unlinking the old
91       copy and putting a new copy in place. Most tools such as
92       <code>rdist</code> and <code>mv</code> do this. The reason why this
93       modules doesn't take care of changes to the files is that this check
94       would need an extra <code>stat()</code> every time which is a waste
95       and against the intent of I/O reduction.</p>
96     </section>
97
98     <section><title>CacheFile Directive</title>
99
100       <p>The <directive module="mod_file_cache">CacheFile</directive>
101       directive of <module>mod_file_cache</module> opens an active
102       <em>handle</em> or <em>file descriptor</em> to the file (or files)
103       listed in the configuration directive and places these open file
104       handles in the cache. When the file is requested, the server
105       retrieves the handle from the cache and passes it to the
106       <code>sendfile()</code> (or <code>TransmitFile()</code> on Windows),
107       socket API.</p>
108
109       <!-- XXX
110       <p>Insert more details about sendfile API...</p>
111       -->
112
113       <p>This file handle caching is done once at server start or
114       restart, only. So whenever one of the cached files changes on
115       the filesystem you <em>have</em> to restart the server (see the
116       <a href="../stopping.html">Stopping and Restarting</a>
117       documentation). To reiterate that point: if the files are
118       modified <em>in place</em> without restarting the server you
119       may end up serving requests that are completely bogus. You
120       should update files by unlinking the old copy and putting a new
121       copy in place. Most tools such as <code>rdist</code> and
122       <code>mv</code> do this.</p>
123     </section>
124
125     <note><title>Note</title>
126       <p>Don't bother asking for a directive which recursively
127       caches all the files in a directory. Try this instead... See the 
128       <directive module="core">Include</directive> directive, and consider
129       this command:</p>
130
131       <example>
132         find /www/htdocs -type f -print \<br />
133         | sed -e 's/.*/mmapfile &amp;/' &gt; /www/conf/mmap.conf
134       </example>
135     </note>
136 </section>
137
138 <directivesynopsis>
139 <name>MMapFile</name>
140 <description>Map a list of files into memory at startup time</description>
141 <syntax>MMapFile <var>file-path</var> [<var>file-path</var>] ...</syntax>
142 <contextlist><context>server config</context></contextlist>
143
144 <usage>
145     <p>The <directive>MMapFile</directive> directive maps one or more files
146     (given as whitespace separated arguments) into memory at server
147     startup time. They are automatically unmapped on a server
148     shutdown. When the files have changed on the filesystem at
149     least a <code>HUP</code> or <code>USR1</code> signal should be send to
150     the server to re-<code>mmap()</code> them.</p>
151
152     <p>Be careful with the <var>file-path</var> arguments: They have
153     to literally match the filesystem path Apache's URL-to-filename
154     translation handlers create. We cannot compare inodes or other
155     stuff to match paths through symbolic links <em>etc.</em>
156     because that again would cost extra <code>stat()</code> system
157     calls which is not acceptable. This module may or may not work
158     with filenames rewritten by <module>mod_alias</module> or
159     <module>mod_rewrite</module>.</p>
160
161     <example><title>Example</title>
162       MMapFile /usr/local/apache/htdocs/index.html
163     </example>
164 </usage>
165 </directivesynopsis>
166
167 <directivesynopsis>
168 <name>CacheFile</name>
169 <description>Cache a list of file handles at startup time</description>
170 <syntax>CacheFile <var>file-path</var> [<var>file-path</var>] ...</syntax>
171 <contextlist><context>server config</context></contextlist>
172
173 <usage>
174     <p>The <directive>CacheFile</directive> directive opens handles to
175     one or more files (given as whitespace separated arguments) and
176     places these handles into the cache at server startup
177     time. Handles to cached files are automatically closed on a server
178     shutdown.  When the files have changed on the filesystem, the
179     server should be restarted to re-cache them.</p>
180
181     <p>Be careful with the <var>file-path</var> arguments: They have
182     to literally match the filesystem path Apache's URL-to-filename
183     translation handlers create. We cannot compare inodes or other
184     stuff to match paths through symbolic links <em>etc.</em>
185     because that again would cost extra <code>stat()</code> system
186     calls which is not acceptable. This module may or may not work
187     with filenames rewritten by <module>mod_alias</module> or
188     <module>mod_rewrite</module>.</p>
189
190     <example><title>Example</title>
191       CacheFile /usr/local/apache/htdocs/index.html
192     </example>
193 </usage>
194 </directivesynopsis>
195
196 </modulesynopsis>