📄 mod_mem_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_mem_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="mailto:csfrank@citiz.net">金步国</a> | 本篇译稿最后更新:2006年1月26日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_mem_cache</h1>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>基于内存的缓冲管理器</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>mem_cache_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_mem_cache.c</td></tr>
</table>
<h3>概述</h3>
<p>本模块需要<code class="module"><a href="../mod/mod_cache.html">mod_cache</a></code>提供的服务。它作为<code class="module"><a href="../mod/mod_cache.html">mod_cache</a></code>的辅助模块工作,以提供基于内存的存储管理。<code class="module"><a href="../mod/mod_mem_cache.html">mod_mem_cache</a></code>模块可以按两种方法来配置:缓存打开的文件描述符,或缓存堆中的对象。<code class="module"><a href="../mod/mod_mem_cache.html">mod_mem_cache</a></code>大多数情况下用于缓存本地生成的内容,或是在<code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code>配置成<code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code>方式(也就是<dfn>反向代理</dfn>)时后端服务器产生的内容。</p>
<p>被缓存的内容通过基于URI的键被保存到缓冲区或从缓冲区取出。带访问保护的内容不会被缓存。</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheMaxObjectCount" id="MCacheMaxObjectCount">MCacheMaxObjectCount</a> <a name="mcachemaxobjectcount" id="mcachemaxobjectcount">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>最大缓存对象数</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMaxObjectCount <var>value</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMaxObjectCount 1009</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>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
<p><code class="directive">MCacheMaxObjectCount</code>指令设定最大缓存对象数。这个值用来生成开放哈希表。如果一个新的对象要被插入缓存,而此时缓存的最大缓存对象数已达到极限,原来缓存的某个对象会被移走以允许新对象插入缓存。具体哪个对象被移走,是通过<code class="directive"><a href="#mcacheremovalalgorithm">MCacheRemovalAlgorithm</a></code>指令指定的算法来确定的。</p>
<div class="example"><h3>示例</h3><p><code>
MCacheMaxObjectCount 13001
</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="MCacheMaxObjectSize" id="MCacheMaxObjectSize">MCacheMaxObjectSize</a> <a name="mcachemaxobjectsize" id="mcachemaxobjectsize">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>缓存允许的最大文档大小(字节)</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMaxObjectSize <var>bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMaxObjectSize 10000</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>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
<p><code class="directive">MCacheMaxObjectSize</code>指令设定允许缓存的最大文档大小(以Byte为单位)。</p>
<div class="example"><h3>示例</h3><p><code>
MCacheMaxObjectSize 6400000
</code></p></div>
<div class="note"><h3>注意</h3>
<p><code class="directive">MCacheMaxObjectSize</code>的值必须大于<code class="directive"><a href="#mcacheminobjectsize">MCacheMinObjectSize</a></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="MCacheMaxStreamingBuffer" id="MCacheMaxStreamingBuffer">MCacheMaxStreamingBuffer</a> <a name="mcachemaxstreamingbuffer" id="mcachemaxstreamingbuffer">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>内存中允许缓冲的最大流式响应字节长度</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMaxStreamingBuffer <var>size_in_bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMaxStreamingBuffer 100000与MCacheMaxObjectSize中的小者</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>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
<p><code class="directive">MCacheMaxStreamingBuffer</code>内存中允许缓冲的最大流式响应字节长度,以决定这个流式响应是否太长而不能被缓存。流式响应是指整个响应内容无法完整地得到,并且<code>Content-Length</code>也末知的响应。流式响应的来源包括代理的响应内容和CGI脚本的输出。默认情况下,除非响应头包含<code>Content-Length</code>信息,否则流式响应<em>不会</em>被缓存。这样做是为了避免使用大量内存缓存那些最终因为太长而不能缓存的响应。而<code class="directive">MCacheMaxStreamingBuffer</code>指令允许缓存不含<code>Content-Length</code>的流式响应,直到达到其指定的值。如果达到了最大流式响应可缓冲长度,已经被缓存的内容将会被释放,缓存也不再继续。</p>
<div class="note"><h3>注意:</h3>
<p>对<code class="directive">MCacheMaxStreamingBuffer</code>使用一个非零值不会对响应传送到客户产生延迟。当<code class="module"><a href="../mod/mod_mem_cache.html">mod_mem_cache</a></code>模块将流式化的内容复制到缓冲区的同时会将数据块传送到下一个输入点以传送给客户端。</p>
</div>
<div class="example"><p><code>
# 指定最大流式响应可缓冲长度为 64KB<br />
MCacheMaxStreamingBuffer 65536
</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="MCacheMinObjectSize" id="MCacheMinObjectSize">MCacheMinObjectSize</a> <a name="mcacheminobjectsize" id="mcacheminobjectsize">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>允许缓存的最小文档大小(字节)</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMinObjectSize <var>bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMinObjectSize 0</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>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
<p><code class="directive">MCacheMinObjectSize</code>指令设定允许缓存的最小文档大小。</p>
<div class="example"><h3>示例</h3><p><code>
MCacheMinObjectSize 10000
</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="MCacheRemovalAlgorithm" id="MCacheRemovalAlgorithm">MCacheRemovalAlgorithm</a> <a name="mcacheremovalalgorithm" id="mcacheremovalalgorithm">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>定义在需要时哪个文档被移出缓存的算法</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheRemovalAlgorithm LRU|GDSF</code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheRemovalAlgorithm GDSF</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>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
<p><code class="directive">MCacheRemovalAlgorithm</code>指令定义在需要时哪个文档被移出缓存。可以有两种选择:</p>
<dl>
<dt><code>LRU</code> (最近最少使用)</dt>
<dd><code>LRU</code> 指定最长时间没有用到的对象将在必要的时候移出缓存。</dd>
<dt><code>GDSF</code> (GreadyDual-Size)</dt>
<dd><code>GDSF</code> 基于缓存命中率和文档大小计算优先级。在必要时,优先级最低的文档被移出缓存。</dd>
</dl>
<div class="example"><h3>示例</h3><p><code>
MCacheRemovalAlgorithm GDSF<br />
MCacheRemovalAlgorithm LRU
</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="MCacheSize" id="MCacheSize">MCacheSize</a> <a name="mcachesize" id="mcachesize">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>缓存允许使用的最大内存量,以KB为单位</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheSize <var>KBytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheSize 100</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>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
<p><code class="directive">MCacheSize</code>指令设定缓存允许使用的最大内存量,以KB(1024-byte)为单位。如果一个新的比缓存剩余内存量大的对象要插入缓存,那么原来缓存内的对象会被移走,直到这个新的对象能被插入缓冲区。具体哪个对象被移走,是通过<code class="directive"><a href="#mcacheremovalalgorithm">MCacheRemovalAlgorithm</a></code>指令指定的算法来确定的。</p>
<div class="example"><h3>示例</h3><p><code>
MCacheSize 700000
</code></p></div>
<div class="note"><h3>注意</h3>
<p><code class="directive">MCacheSize</code>的值必须比<code class="directive"><a href="#mcachemaxobjectsize">MCacheMaxObjectSize</a></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 + -