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