亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Verzeichnis suchen
Smarty模板編譯引擎 I.開始 第一章. 什么是Smarty? 第二章. 安裝 要求 基本安裝 擴(kuò)展設(shè)置 II.模板設(shè)計者篇 第三章.基本語法 注釋 函數(shù) 屬性 第四章.變量 從PHP分配的變量 Associative arrays Array indexes Objects 從配置文件讀取的變量 {$smarty}保留變量 Request variables {$smarty.now} {$smarty.const} {$smarty.capture} {$smarty.config} {$smarty.section} {$smarty.template} 第五章.變量調(diào)節(jié)器 capitalize count_characters cat count_paragraphs count_sentences count_words date_format default escape indent lower nl2br regex_replace replace spacify string_format strip strip_tags truncate upper wordwrap 第六章.組合修改器 第七章.內(nèi)建函數(shù) capture config_load foreach include include_php insert if ldelim literal php section index index_prev index_next iteration first last rownum loop show total strip 第八章.自定義函數(shù) assign counter cycle debug eval fetch html_checkboxes html_image html_options html_radios html_select_date html_select_time html_table math mailto popup_init popup textformat 第九章.配置文件 第十章.調(diào)試控制臺 III.模板程序員篇 第十一章 常量 SMARTY_DIR 第十二章 變量 $template_dir $compile_dir $config_dir $plugins_dir $debugging $debug_tpl $debugging_ctrl $global_assign $undefined $autoload_filters $compile_check $force_compile $caching $cache_dir $cache_lifetime $cache_handler_func $cache_modified_check $config_overwrite $config_booleanize $config_read_hidden $config_fix_newlines $default_template_handler_func $php_handling $security $secure_dir $security_settings $trusted_dir $left_delimiter $right_delimiter $compiler_class $request_vars_order $compile_id $use_sub_dirs $default_modifiers $default_resource_type 第十三章.方法 append append_by_ref assign assign_by_ref clear_all_assign clear_all_cache clear_assign clear_cache clear_compiled_tpl clear_config config_load display fetch get_config_vars get_registered_object get_template_vars is_cached load_filter register_block register_compiler_function register_function register_modifier register_object register_outputfilter register_postfilter register_prefilter register_resource trigger_error template_exists unregister_block unregister_compiler_function unregister_function unregister_modifier unregister_object unregister_outputfilter unregister_postfilter unregister_prefilter unregister_resource 第十四章.緩存 Setting Up Caching Multiple Caches Per Page Cache Groups Controlling Cacheability of Plugins' Output 第十五章.高級特點(diǎn) Objects Prefilters Postfilters Output Filters Cache Handler Function Resources Templates from $template_dir Templates from any directory Templates from other sources Default template handler function 第十六章.以插件擴(kuò)展Smarty How Plugins Work Naming Conventions Writing Plugins Template Functions Modifiers Block Functions Compiler Functions Prefilters/Postfilters Output Filters Resources Inserts Ⅳ.高級特點(diǎn) 第十七章.疑難解答 Smarty/PHP errors 第18章.使用技巧和經(jīng)驗 Blank Variable Handling Default Variable Handling Passing variable title to header template Dates WAP/WML Componentized Templates Obfuscating E-mail Addresses 第十九章. 相關(guān)資源 第二十章. 漏洞
Figuren

Chapter 14. Caching [緩存]

Table of Contents [內(nèi)容列表]
Setting Up Caching [建立緩存]
Multiple Caches Per Page [每頁多個緩存]
Cache Groups [緩存集合]
Controlling Cacheability of Plugins' Output [控制插件輸出的緩沖能力]

Caching is used to speed up a call to display() or fetch() by saving its output to a file. If a cached version of the call is available, that is displayed instead of regenerating the output. Caching can speed things up tremendously, especially templates with longer computation times. Since the output of display() or fetch() is cached, one cache file could conceivably be made up of several template files, config files, etc.
緩存被用來保存一個文檔的輸出從而加速display()或fetch()函數(shù)的執(zhí)行。如果一個函數(shù)被加進(jìn)緩存,那么實際輸出的內(nèi)容將用緩存來代替。緩存可讓事物非??焖俚膱?zhí)行,特別是帶有長計算時間的模板。一旦display()或fetch()用緩存輸出,那么一個緩存文檔將非常容易用幾個模板文檔或是配置文檔等來組成〔功力不小〕。

Since templates are dynamic, it is important to be careful what you are caching and for how long. For instance, if you are displaying the front page of your website that does not change its content very often, it might work well to cache this page for an hour or more. On the other hand, if you are displaying a page with a weather map containing new information by the minute, it would not make sense to cache this page.
一旦模板是動態(tài)〔應(yīng)該不難理解〕的,哪些文檔你加了緩存,緩存時間多長都是很重要的。舉個例子,比如你站點(diǎn)的首頁內(nèi)容不是經(jīng)常更改,那么對首頁緩存一個小時或是更長都可得到很好效果。相反,幾分鐘就要更新一下信息的天氣地圖頁面,用緩存就不好了。

Setting Up Caching [建立緩存]

The first thing to do is enable caching. This is done by setting $caching = true (or 1.)
首先要做的就是讓緩存可用。這就要設(shè)置$caching = true(或 1.)

Example 14-1. enabling caching
例14-1.使緩存可用

require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = true;

$smarty->display('index.tpl');

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. Upon the next call to display('index.tpl'), the cached copy will be used instead of rendering the template again.
建立緩存后,display('index.tpl')函數(shù)會把模板返回原來狀態(tài)〔沒緩存〕,也會把輸出保存copy〖n.名詞〗到$cache_dir.下次調(diào)用display('index.tpl'),保存的緩存copy〖n.〗會被再用來代替原來的模板。

Technical Note: The files in the $cache_dir are named similar to the template name. Although they end in the ".php" extention, they are not really executable php scripts. Do not edit these files!
技術(shù)提示:在$chche_dir目錄里的文檔命名跟模板一致。盡管是用.php作為擴(kuò)展名,但并不會被當(dāng)作php代碼來解析。所以不要去修改它。

Each cached page has a limited lifetime determined by $cache_lifetime. The default value is 3600 seconds, or 1 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 the documentation on $cache_lifetime for details.
每個緩存頁都有一個用$cache_lifetime來控制的會話期。初始值是3600秒,就是一小時〔廢話嘛〕。會話期結(jié)束,緩存就會重建。你可以通過設(shè)置$caching=2來控制單個緩存文件各自的的過期時間。祥細(xì)內(nèi)容察看$cache_lifetime里面的列表。

Example 14-2. setting cache_lifetime per cache
例14-2 設(shè)置單個緩存會話期〔時間〕

require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = 2; // lifetime is per cache

// set the cache_lifetime for index.tpl to 5 minutes
$smarty->cache_lifetime = 300;
$smarty->display('index.tpl');

// set the cache_lifetime for home.tpl to 1 hour
$smarty->cache_lifetime = 3600;
$smarty->display('home.tpl');


// NOTE: the following $cache_lifetime setting will not work when $caching = 2.
//提示:在$chching=2后面的$chche_lifetime不會起作用。
// The cache lifetime for home.tpl has already been set
// to 1 hour, and will no longer respect the value of $cache_lifetime.
// home.tpl的緩存會話期設(shè)為1小時后,不會再按$cache_lifetime的值改變。
// The home.tpl cache will still expire after 1 hour.
// home.tpl的緩存會在1小時后結(jié)束。$smarty->cache_lifetime = 30; // 30 seconds
$smarty->display('home.tpl');

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, leave $compile_check set to false.
如果$compile_check可用,每個跟緩存文檔相關(guān)的模板文檔和配置文檔都會被檢查來確定是否需要修改。在緩存產(chǎn)生后,改動任何文檔,緩存也跟著更新改動。設(shè)置$compile_check為false,這是實現(xiàn)最佳性能的最小改動〔應(yīng)該是這樣:D〕。

Example 14-3. enabling $compile_check
例14-3.可用$compile_check

require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = true;
$smarty->compile_check = true;

$smarty->display('index.tpl');

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 = false (or 0.)
一旦$force_compile可用,緩存文檔會一直重建。這有效地關(guān)閉緩存。$force_compile只是用來調(diào)試,更有效關(guān)閉緩存的方法是讓$caching = false(或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.
is_cached()函數(shù)可用來測試一個模板是否有有效的緩存。如果一個緩存模板需要從數(shù)據(jù)庫中獲取數(shù)據(jù),可以用這個函數(shù)來跳過這個過程。

Example 14-4. using is_cached()
例14-4.使用is_cached()

require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = true;

if(!$smarty->is_cached('index.tpl')) {
	// No cache available, do variable assignments here.
	$contents = get_database_contents();
	$smarty->assign($contents);
}

$smarty->display('index.tpl');

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 right side of the page. By using an insert function for the banner, you can keep this element dynamic within the cached content. See the documentation on insert for details and examples.
你可以插入模板函數(shù)insert來使部分頁面動態(tài)化。除了在右下方顯示的標(biāo)語外整個頁面都可以緩存。在緩存內(nèi)容里面可以插入函數(shù)來使標(biāo)語也動態(tài)化。查看相關(guān)文檔關(guān)于insert的細(xì)節(jié)和例子。

You can clear all the cache files with the clear_all_cache() function, or individual cache files (or groups) with the clear_cache() function.
你可以用clear_all_cache()來清除所有緩存,或用clear_cache()來清除單個緩存文檔。

Example 14-5. clearing the cache
例14-5.清除緩存

require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = true;

// clear out all cache files
$smarty->clear_all_cache();

// clear only cache for index.tpl
$smarty->clear_cache('index.tpl');

$smarty->display('index.tpl');
Vorheriger Artikel: N?chster Artikel: