<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. 美麗的煙花盛會作文

    時間:2025-10-18 23:30:55 煙花 我要投稿

    美麗的煙花盛會作文

      一、使用緩存

    美麗的煙花盛會作文

      要開啟smarty的緩存,只需將caching設為true,并指定cache_dir即可.

      使用cache_lefetime指定緩存生存時間,單位為秒

      要對相同頁面生成多個不同的緩存,在display或fetch中加入第二參數cache_id,如$smarty->display('index.tpl',$my_cache_id);此特性可用于對不同的$_GET進行不同的緩存

      二、清除緩存

      clear_all_cache();/pic/p>

      clear_cache('index.tpl');/pic/p>

      clear_cache('index.tpl',cache_id);/pic/p>

      三、使用自定義緩存方式

      設置cache_handler_func使用自定義的函數處理緩存

      如:

      $smarty->cache_handler_func = "myCache";

      function myCache($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null){

      }

      該函數的一般是根椐$action來判斷緩存當前操作:

      switch($action){

      case "read":/pic/p>

      case "write":/pic/p>

      case "clear":/pic/p>

      }

      一般使用md5($tpl_file.$cache_id.$compile_id)作為唯一的cache_id

      如果需要,可使用gzcompress和gzuncompress來壓縮和解壓

      四、局部關閉緩存

      要在某些區域使緩存失效(只對需要的緩存),有幾種方法:

      insert:

      定義一個insert標簽要使用的處理函數,函數名格式為:insert_xx(array $params, object &$smarty)其中的xx是insert的name,也就是說,如果你定義的函數為insert_abc,則模板中使用方法為{insert name='abc'}

      參數通過$params傳入

      也可以做成insert插件,文件名命名為:insert.xx.php,函數命名為:smarty_insert_aa($params,&$smarty),xx定義同上

      register_block:

      定義一個block:smarty_block_name($params,$content, &$smarty){return $content;} /pic/p>

      注冊block:$smarty->register_block('name', 'smarty_block_name', false); /pic/p>

      模板寫法:{name}內容{/name}

      寫成block插件:

      1)定義一件插件函數:block.cacheless.php,放在smarty的plugins目錄

      block.cacheless.php的內容如下:

      

      function smarty_block_cacheless($param, $content, &$smarty) {

      return $content;

      }

      ?>

      2) 編寫程序及模板

      示例程序:testCacheLess.php

      

      include('Smarty.class.php');

      $smarty = new Smarty;

      $smarty->caching=true;

      $smarty->cache_lifetime = 6;

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

      ?>

      所用的模板:cache.tpl

      已經緩存的:{$smarty.now}

      {cacheless}

      沒有緩存的:{$smarty.now}

      {/cacheless}

    【美麗的煙花盛會作文】相關文章:

    煙花_美麗的煙花作文02-15

    【精選】美麗的煙花作文01-04

    美麗的煙花作文(經典)04-16

    美麗的煙花作文10-02

    美麗的煙花作文08-05

    美麗的煙花作文[精選]02-19

    美麗的煙花作文(熱門)01-18

    [集合]美麗的煙花作文01-07

    美麗的煙花作文【優秀】01-03

    (通用)美麗的煙花作文02-19

    • 相關推薦
    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人