<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="caching.html" accesskey="P">Prev</a></td><td width="50%" align="center" valign="bottom"/><td width="25%" align="right" valign="bottom"><a href="caching.multiple.caches.html" accesskey="N">Next</a></td></tr></table> Setting Up Caching [建立緩存] The first thing to do is enable caching by setting $caching = 1 (or 2). 首先啟用緩存。設置$caching = 1(或 2) 。 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td> <div class="EXAMPLE"> <a name="AEN3141" id="AEN3141"> </a> <b><span class="PROGRAMLISTING">Example 14.1. Enabling caching</span><br/> 例14-1.啟動緩存</b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <pre class="PROGRAMLISTING">&lt;?phprequire('Smarty.class.php');$smarty = new Smarty;$smarty-&gt;caching = Smarty::CACHING_LIFETIME_CURRENT;$smarty-&gt;display('index.tpl');?&gt;</pre> </td> </tr></table></div> </td> </tr></table> With caching enabled, the function call to display('index.tpl') will render the template as usual,but also saves a copy of its output to a file (a cached copy) in the $cache_dir. On the next call to display('index.tpl'), the cached copy will be used instead of rendering the template again. 緩存啟動后,當函數調用display('index.tpl')時會照常渲染模板,同時還會將其輸出保存為一個緩存文件放到[$cache_dir](#)目錄下。當下次調用display('index.tpl')時,程序將直接取出緩存文件,而不是再次渲染模板。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 技術提示 </caption> <tr><td><p>Technical Note<br/> The files in the $cache_dir are named similar to the template name. Although they end in the .php extention, they are not intended to be directly executable. Do not edit these files!</p> <p>在$chche_dir目錄里的文件命名與模板一致。盡管使用.php作為擴展名,但并不會當作php代碼執行。所以不要去修改它。</p></td> </tr></table> Each cached page has a limited lifetime determined by $cache_lifetime. The default value is 3600 seconds ie an hour. After that time expires, the cache is regenerated. It is possible to give individual caches their own expiration time by setting $caching=2. See $cache_lifetime for more details. 每個緩存頁面由[$cache_lifetime](#)變量控制文件的生存周期。初始值是3600秒,就是一小時〔廢話嘛〕。周期結束,緩存就會重建。你可以通過設置$caching=2來控制單個緩存文件自己的生存周期。詳情查看$cache_lifetime里面的列表。 <table width="80%" class="note"><caption> 譯注 </caption> <tr><td>$smarty-&gt;caching設置為1、Smarty::CACHING_LIFETIME_CURRENT和Smarty::CACHING_LIFETIME_SAVED有什么不同?<br/> 設為1僅表示開啟緩存,使用默認值$caching_time = 3600s,如果緩存周期到期,則不再使用緩存;而Smarty::CACHING_LIFETIME_CURRENT則會先判斷是否過期,如果沒有則繼續使用當前緩存,如果過期則重新建立緩存,php腳本內設置的$caching_time對所有緩存有效;而Smarty::CACHING_LIFETIME_SAVED用以設置php腳本內的單個緩存,比如加載進來的模板緩存。</td> </tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td> <div class="EXAMPLE"> <a name="AEN3142" id="AEN3142"> </a> <b><span class="PROGRAMLISTING">Example 14.2. Setting $cache_lifetime per cache</span><br/> 例14-2 設置單個緩存周期 </b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <pre class="PROGRAMLISTING">&lt;?phprequire('Smarty.class.php');$smarty = new Smarty;$smarty-&gt;caching = Smarty::CACHING_LIFETIME_SAVED; // lifetime is per cache&#13; // set the cache_lifetime for index.tpl to 5 minutes$smarty-&gt;cache_lifetime = 300;$smarty-&gt;display('index.tpl');&#13; // set the cache_lifetime for home.tpl to 1 hour$smarty-&gt;cache_lifetime = 3600;$smarty-&gt;display('home.tpl');&#13; // NOTE: the following $cache_lifetime setting will not work when $caching = 2.// The cache lifetime for home.tpl has already been set// to 1 hour, and will no longer respect the value of $cache_lifetime.// The home.tpl cache will still expire after 1 hour.//注意:當設$caching=2,接下來的$cache_lifetime設置并不會影響home.tpl工作,因為home.tpl緩存周期在前面已經設為1小時,//其不再理會后面$cache_lifetime的值,home.tpl緩存周期仍為1小時。$smarty-&gt;cache_lifetime = 30; // 30 seconds$smarty-&gt;display('home.tpl');?&gt;</pre></td> </tr></table></div> </td> </tr></table> If $compile_check is enabled, every template file and config file that is involved with the cache file is checked for modification. If any of the files have been modified since the cache was generated, the cache is immediately regenerated. This is a slight overhead so for optimum performance, set $compile_check to FALSE. 如果啟用[$compile_check](#),將會檢查緩存文件的原模板、配置文件是否經過修改。在緩存產生后,如果原文件有任何改動,其緩存文件也立即隨著更新。設置[$compile_check](#)為false,可以做到以最小的開銷實現最佳的性能(應該是這樣:D)。 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td> <div class="EXAMPLE"> <a name="AEN3685"> </a> <b><span class="PROGRAMLISTING">Example 14.3. Enabling $compile_check</span><br/> 例14-3.啟動$compile_check </b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <pre class="PROGRAMLISTING">&lt;?phprequire('Smarty.class.php');$smarty = new Smarty;$smarty-&gt;caching = Smarty::CACHING_LIFETIME_CURRENT;$smarty-&gt;compile_check = true;$smarty-&gt;display('index.tpl');?&gt;</pre></td> </tr></table></div> </td> </tr></table> If $force_compile is enabled, the cache files will always be regenerated. This effectively turns off caching. $force_compile is usually for debugging purposes only, a more efficient way of disabling caching is to set [$caching](#) = 0. The is_cached() function can be used to test if a template has a valid cache or not. If you have a cached template that requires something like a database fetch, you can use this to skip that process. 如果啟用[$force_compile](#),緩存文件會一直重建。這樣做實際上等于關閉了緩存。$force_compile只是用來調試,一個更關閉緩存的更好方法是設$caching = 0。 [is_cached()](#)函數可用來測試一個模板是否建立了有效的緩存。如果緩存模板需要發送一些請求,如從數據庫中獲取數據,可以用這個函數來跳過再次請求的過程。 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td> <div class="EXAMPLE"> <strong><a name="AEN31444" id="AEN31444"> </a>Example 14.4. Using is_cached()</strong><b><br/> 例14-4.使用is_cached() </b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <pre class="PROGRAMLISTING">&lt;?phprequire('Smarty.class.php');$smarty = new Smarty;$smarty-&gt;caching = Smarty::CACHING_LIFETIME_CURRENT;if(!$smarty-&gt;is_cached('index.tpl')) { // No cache available, do variable assignments here. $contents = get_database_contents(); $smarty-&gt;assign($contents);}$smarty-&gt;display('index.tpl');?&gt;</pre></td> </tr></table></div> </td> </tr></table> You can keep parts of a page dynamic with the {insert} template function. Let's say the whole page can be cached except for a banner that is displayed down the side of the page. By using the {insert} function for the banner, you can keep this element dynamic within the cached content. See the documentation on {insert} for more details and examples. You can clear all the cache files with the clear_all_cache() function, or individual cache files and groups with the clear_cache() function. 你可以插入模板函數[{insert}](#)來使部分頁面動態化。假如除頁腳的banner廣告須動態顯示外,其它頁面都可以緩存。那么就用{insert}函數插入banner,當頁面緩存后,它還是一個動態顯示的元素,換句話說,內容緩存并未影響到banner廣告的更新顯示。詳情查看[{insert}](#)相關文檔。 你可以用[clear_all_cache()](#)來清除所有緩存,或用[clear_cache()](#)來清除單個緩存文件或緩存組。 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td> <div class="EXAMPLE"> <a name="AEN3145" id="AEN3145"> </a> <b>Example 14-5. clearing the cache<br/> 例14-5.清除緩存 </b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <pre class="PROGRAMLISTING">&lt;?phprequire('Smarty.class.php');$smarty = new Smarty;$smarty-&gt;caching = Smarty::CACHING_LIFETIME_CURRENT;// clear only cache for index.tpl$smarty-&gt;clear_cache('index.tpl');// clear out all cache files$smarty-&gt;clear_all_cache();$smarty-&gt;display('index.tpl');?&gt;</pre></td> </tr></table></div> </td> </tr></table> <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="caching.html" accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="caching.multiple.caches.html" accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Caching<br/> 緩存 </td> <td width="34%" align="center" valign="top"><a href="smarty.for.programmers.html" accesskey="U">Up</a></td> <td width="33%" align="right" valign="top">Multiple Caches Per Page<br/> 多重緩存 </td> </tr></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看