📄 mod_file_cache.html
字号:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="Apache, 中文, 手册, 中文版, 中文手册, 中文版手册, 参考手册, 中文参考手册, 金步国" />
<meta name="description" content="Apache 2.2 中文版参考手册" />
<meta name="author" content="金步国" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>mod_file_cache - Apache 2.2 中文版参考手册</title>
</head>
<body><div id="page-header">
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./index.html"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
<div id="path"><a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">文档</a> > <a href="../index.html">版本2.2</a> > <a href="./index.html">模块</a></div>
<div id="translation-info"> <a href="../translator_announcement.html#thanks">致谢</a> | <a href="../translator_announcement.html#announcement">译者声明</a> | 本篇译者:<<a href="../translator_announcement.html#join">虚位以待</a>> | 本篇译稿完成时间:?年?月?日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_file_cache</h1>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>提供文件描述符缓存支持,从而提高Apache性能</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>实验(X)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>file_cache_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_file_cache.c</td></tr>
</table>
<h3>概述</h3>
<div class="warning">
This module should be used with care. You can easily create a broken
site using <code class="module"><a href="../mod/mod_file_cache.html">mod_file_cache</a></code>, so read this document
carefully.
</div>
<p><em>Caching</em> frequently requested files that change very
infrequently is a technique for reducing server load.
<code class="module"><a href="../mod/mod_file_cache.html">mod_file_cache</a></code> provides two techniques for caching
frequently requested <em>static</em> files. Through configuration
directives, you can direct <code class="module"><a href="../mod/mod_file_cache.html">mod_file_cache</a></code> to either
open then <code>mmap()</code> a file, or to pre-open a file and save
the file's open <em>file handle</em>. Both techniques reduce server
load when processing requests for these files by doing part of the work
(specifically, the file I/O) for serving the file when the
server is started rather than during each request.</p>
<p>注意:You cannot use this for speeding up CGI programs or
other files which are served by special content handlers. It
can only be used for regular files which are usually served by
the Apache core content handler.</p>
<p>This module is an extension of and borrows heavily from the
<code>mod_mmap_static</code> module in Apache 1.3.</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="using" id="using">Using mod_file_cache</a></h2>
<p><code class="module"><a href="../mod/mod_file_cache.html">mod_file_cache</a></code> caches a list of statically
configured files via <code class="directive"><a href="#mmapfile">MMapFile</a></code>或<code class="directive"><a href="#cachefile">CacheFile</a></code> directives in the main server configuration.</p>
<p>Not all platforms support both directives. For example, Apache
on Windows does not currently support the <code class="directive"><a href="#mmapstatic">MMapStatic</a></code> directive, while
other platforms, like AIX, support both. You will receive an error
message in the server error log if you attempt to use an
unsupported directive. If given an unsupported directive, the
server will start but the file will not be cached. On platforms
that support both directives, you should experiment with both to
see which works best for you.</p>
<h3>MMapFile Directive</h3>
<p><code class="directive"><a href="#mmapfile">MMapFile</a></code>
directive of <code class="module"><a href="../mod/mod_file_cache.html">mod_file_cache</a></code> maps a list of
statically configured files into memory through the system call
<code>mmap()</code>. This system call is available on most modern
Unix derivates, but not on all. There are sometimes system-specific
limits on the size and number of files that can be
<code>mmap()</code>ed, experimentation is probably the easiest way
to find out.</p>
<p>This <code>mmap()</code>ing is done once at server start or
restart, only. So whenever one of the mapped files changes on the
filesystem you <em>have</em> to restart the server (see the <a href="../stopping.html">Stopping and Restarting</a> documentation).
To reiterate that point: if the files are modified <em>in place</em>
without restarting the server you may end up serving requests that
are completely bogus. You should update files by unlinking the old
copy and putting a new copy in place. Most tools such as
<code>rdist</code>和<code>mv</code> do this. The reason why this
modules doesn't take care of changes to the files is that this check
would need an extra <code>stat()</code> every time which is a waste
and against the intent of I/O reduction.</p>
<h3>CacheFile Directive</h3>
<p><code class="directive"><a href="#cachefile">CacheFile</a></code>
directive of <code class="module"><a href="../mod/mod_file_cache.html">mod_file_cache</a></code> opens an active
<em>handle</em>或<em>file descriptor</em> to the file (or files)
listed in the configuration directive and places these open file
handles in the cache. When the file is requested, the server
retrieves the handle from the cache and passes it to the
<code>sendfile()</code> (or <code>TransmitFile()</code> on Windows),
socket API.</p>
<p>This file handle caching is done once at server start or
restart, only. So whenever one of the cached files changes on
the filesystem you <em>have</em> to restart the server (see the
<a href="../stopping.html">Stopping and Restarting</a>
documentation). To reiterate that point: if the files are
modified <em>in place</em> without restarting the server you
may end up serving requests that are completely bogus. You
should update files by unlinking the old copy and putting a new
copy in place. Most tools such as <code>rdist</code>和<code>mv</code> do this.</p>
<div class="note"><h3>注意</h3>
<p>Don't bother asking for a directive which recursively
caches all the files in a directory. Try this instead... See the
<code class="directive"><a href="../mod/core.html#include">Include</a></code> directive, and consider
this command:</p>
<div class="example"><p><code>
find /www/htdocs -type f -print \<br />
| sed -e 's/.*/mmapfile &/' > /www/conf/mmap.conf
</code></p></div>
</div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="CacheFile" id="CacheFile">CacheFile</a> <a name="cachefile" id="cachefile">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Cache a list of file handles at startup time</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>CacheFile <var>file-path</var> [<var>file-path</var>] ...</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>实验(X)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_file_cache</td></tr>
</table>
<p><code class="directive">CacheFile</code> directive opens handles to
one or more files (given as whitespace separated arguments) and
places these handles into the cache at server startup
time. Handles to cached files are automatically closed on a server
shutdown. When the files have changed on the filesystem, the
server should be restarted to to re-cache them.</p>
<p>Be careful with the <var>file-path</var> arguments: They have
to literally match the filesystem path Apache's URL-to-filename
translation handlers create. We cannot compare inodes or other
stuff to match paths through symbolic links <em>etc.</em>
because that again would cost extra <code>stat()</code> system
calls which is not acceptable. This module may or may not work
with filenames rewritten by <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code>或<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
<div class="example"><h3>示例</h3><p><code>
CacheFile /usr/local/apache/htdocs/index.html
</code></p></div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MMapFile" id="MMapFile">MMapFile</a> <a name="mmapfile" id="mmapfile">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Map a list of files into memory at startup time</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MMapFile <var>file-path</var> [<var>file-path</var>] ...</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>实验(X)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_file_cache</td></tr>
</table>
<p><code class="directive">MMapFile</code> directive maps one or more files
(given as whitespace separated arguments) into memory at server
startup time. They are automatically unmapped on a server
shutdown. When the files have changed on the filesystem at
least a <code>HUP</code>或<code>USR1</code> signal should be send to
the server to re-<code>mmap()</code> them.</p>
<p>Be careful with the <var>file-path</var> arguments: They have
to literally match the filesystem path Apache's URL-to-filename
translation handlers create. We cannot compare inodes or other
stuff to match paths through symbolic links <em>etc.</em>
because that again would cost extra <code>stat()</code> system
calls which is not acceptable. This module may or may not work
with filenames rewritten by <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code>或<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
<div class="example"><h3>示例</h3><p><code>
MMapFile /usr/local/apache/htdocs/index.html
</code></p></div>
</div>
</div>
<div id="footer">
<p class="apache">本文允许自由使用、分发、转载,但必须保留译者署名;详见:<a href="../translator_announcement.html#announcement">译者声明</a>。</p>
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p></div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -