mod_file_cache.html revision e0b181d3bfa99dfb992df3024b397660cb7afbe9
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin<html xmlns="http://www.w3.org/TR/xhtml1/strict"><head><!--
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin This file is generated from xml source: DO NOT EDIT
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin --><title>mod_file_cache- Apache HTTP Server</title><link rel="stylesheet" type="text/css" href="/style/manual.css"/></head><body><blockquote><div align="center"><img src="/images/sub.gif" alt="[APACHE DOCUMENTATION]"/><h3>Apache HTTP Server Version 2.0</h3></div><h1 align="center">Apache Module mod_file_cache</h1><table bgcolor="#cccccc" cellpadding="0" cellspacing="1"><tr><td><table bgcolor="#ffffff"><tr><td valign="top"><span class="help">Description:</span></td><td>Caches a static list of files in memory</td></tr><tr><td><a class="help" href="module-dict.html#Status">Status:</a></td><td>Experimental</td></tr><tr><td><a class="help" href="module-dict.html#ModuleIdentifier">Module Identifier:</a></td><td>file_cache_module</td></tr></table></td></tr></table><h2>Summary</h2>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinThis module should be used with care. You can easily
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin create a broken site using mod_file_cache, so read this
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin document carefully.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p><em>Caching</em> frequently requested files that change very
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin infrequently is a technique for reducing server load.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mod_file_cache provides two techniques for caching frequently
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin directives, you can direct mod_file_cache to either open then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mmap()a file, or to pre-open a file and save the file's open
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <em>file handle</em>. Both techniques reduce server load when
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin processing requests for these files by doing part of the work
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (specifically, the file I/O) for serving the file when the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin server is started rather than during each request.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>Notice: You cannot use this for speeding up CGI programs or
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin other files which are served by special content handlers. It
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin can only be used for regular files which are usually served by
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin the Apache core content handler.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>This module is an extension of and borrows heavily from the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mod_mmap_static module in Apache 1.3.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin<h2>Directives</h2><ul><li><a href="#cachefile">CacheFile</a></li><li><a href="#mmapfile">MMapFile</a></li></ul><h2>Using mod_file_cache</h2>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p><code><a href="mod_file_cache.html">mod_file_cache</a></code> caches a list of statically
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin configured files via <a class="directive" href="#mmapfile"><code class="directive">MMapFile</code></a> or <a class="directive" href="#cachefile"><code class="directive">CacheFile</code></a> directives in the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin main server configuration.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>Not all platforms support both directives. For example, Apache
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin on Windows does not currently support the <a class="directive" href="#mmapstatic"><code class="directive">MMapStatic</code></a> directive, while
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin other platforms, like AIX, support both. You will receive an error
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin message in the server error log if you attempt to use an
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin unsupported directive. If given an unsupported directive, the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin server will start but the file will not be cached. On platforms
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin that support both directives, you should experiment with both to
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin see which works best for you.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>The <a class="directive" href="#mmapfile"><code class="directive">MmapFile</code></a>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin directive of <code><a href="mod_file_cache.html">mod_file_cache</a></code> maps a list of
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin statically configured files into memory through the system call
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <code>mmap()</code>. This system call is available on most modern
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Unix derivates, but not on all. There are sometimes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin system-specific limits on the size and number of files that can be
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mmap()d, experimentation is probably the easiest way to find
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>This mmap()ing is done once at server start or restart,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin only. So whenever one of the mapped files changes on the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin filesystem you <em>have</em> to restart the server (see the <a href="/stopping.html">Stopping and Restarting</a>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin documentation). To reiterate that point: if the files are
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin modified <em>in place</em> without restarting the server you
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin may end up serving requests that are completely bogus. You
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin should update files by unlinking the old copy and putting a new
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin copy in place. Most tools such as <code>rdist</code> and
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <code>mv</code> do this. The reason why this modules doesn't
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin take care of changes to the files is that this check would need
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin an extra <code>stat()</code> every time which is a waste and
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin against the intent of I/O reduction.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>The <a class="directive" href="#cachefile"><code class="directive">CacheFile</code></a>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin directive of <code><a href="mod_file_cache.html">mod_file_cache</a></code> opens an active
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <em>handle</em> or <em>file descriptor</em> to the file (or files)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin listed in the configuration directive and places these open file
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin handles in the cache. When the file is requested, the server
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin retrieves the handle from the cache and passes it to the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sendfile() (or TransmitFile() on Windows), socket API.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>This file handle caching is done once at server start or
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin restart, only. So whenever one of the cached files changes on
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin the filesystem you <em>have</em> to restart the server (see the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin documentation). To reiterate that point: if the files are
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin modified <em>in place</em> without restarting the server you
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin may end up serving requests that are completely bogus. You
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin should update files by unlinking the old copy and putting a new
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin copy in place. Most tools such as <code>rdist</code> and
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin<blockquote><table><tr><td bgcolor="#e0e5f5"><p align="center"><strong>Note</strong></p> Don't bother asking for a for a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin directive which recursively caches all the files in a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin directory. Try this instead... See the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <a class="directive" href="core.html#include"><code class="directive">Include</code></a> directive, and consider
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin this command:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin | sed -e 's/.*/mmapfile &/' > /www/conf/mmap.conf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin<hr/><h2><a name="CacheFile">CacheFile</a> <a name="cachefile">Directive</a></h2><table bgcolor="#cccccc" border="0" cellspacing="0" cellpadding="1"><tr><td><table bgcolor="#ffffff"><tr><td><strong>Description: </strong></td><td/></tr><tr><td><a class="help" href="directive-dict.html#Syntax">Syntax:</a></td><td>CacheFile
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <em>file-path</em> [<em>file-path</em>] ...</td></tr><tr><td><a class="help" href="directive-dict.html#Context">Context:</a></td><td>server config</td></tr><tr><td><a class="help" href="directive-dict.html#Status">Status:</a></td><td>Experimental</td></tr><tr><td><a class="help" href="directive-dict.html#Module">Module:</a></td><td>mod_file_cache</td></tr></table></td></tr></table>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>The <code class="directive">CacheFile</code> directive opens handles to
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin one or more files (given as whitespace separated arguments) and
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin places these handles into the cache at server startup
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin time. Handles to cached files are automatically closed on a server
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin shutdown. When the files have changed on the filesystem, the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin server should be restarted to to re-cache them.</p>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <p>Be careful with the <em>file-path</em> arguments: They have
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin to literally match the filesystem path Apache's URL-to-filename
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin translation handlers create. We cannot compare inodes or other
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin stuff to match paths through symbolic links <em>etc.</em>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin because that again would cost extra <code>stat()</code> system
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin calls which is not acceptable. This module may or may not work
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin with filenames rewritten by <code><a href="mod_alias.html">mod_alias</a></code> or
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <code><a href="mod_rewrite.html">mod_rewrite</a></code>.</p>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><p align="center"><strong>Example</strong></p><code>
<hr/><h2><a name="MMapFile">MMapFile</a> <a name="mmapfile">Directive</a></h2><table bgcolor="#cccccc" border="0" cellspacing="0" cellpadding="1"><tr><td><table bgcolor="#ffffff"><tr><td><strong>Description: </strong></td><td/></tr><tr><td><a class="help" href="directive-dict.html#Syntax">Syntax:</a></td><td>MMapFile <em>file-path</em> [<em>file-path</em>] ...</td></tr><tr><td><a class="help" href="directive-dict.html#Context">Context:</a></td><td>server config</td></tr><tr><td><a class="help" href="directive-dict.html#Status">Status:</a></td><td>Experimental</td></tr><tr><td><a class="help" href="directive-dict.html#Module">Module:</a></td><td>mod_file_cache</td></tr></table></td></tr></table>