国产女人18毛片水真多18精品, 一区二区三区中文字-亚洲精品女国产, 欧美熟妇老熟妇88888久久久久, 一级毛片免费观看亚洲欧美国产精品,大波霸美女视频,日韩欧美激情V影院,熟女人伦21p,亚洲精品女国产,国产 乱子伦 在线

php-smarty模版引擎中的緩存應用

時間:2025-09-25 11:14:23 php語言 我要投稿

php-smarty模版引擎中的緩存應用

  同學們在學習的時候一定要保持足夠耐心,才能把知識學好。以下百分網(wǎng)小編整理的php smarty模版引擎中的緩存應用實例代碼的介紹,希望對大家有所幫助,更多信息請關注應屆畢業(yè)生網(wǎng)!

  1,Smarty緩存的配置:

  $smarty->cache-dir="目錄名"; /pic/p>

  $smarty->caching=true; /pic/p>

  $smarty->cache_lifetime=60; /pic/p>

  2,Smarty緩存的使用與清除

  $marty->display("cache.tpl",cache_id); /pic/p>

  $marty->clear_all_cache(); /pic/p>

  $marty->clear_cache("index.php"); /pic/p>

  $marty->clear_cache("index.php',cache_id); /pic/p>

  3,Smarty的局部緩存

  第一個: insert_函數(shù)默認是不緩存,這個屬性是不能修改

  使用方法:例子

  index.php中,

  function insert_get_time(){

  return date("Y-m-d H:m:s");

  }

  index.html中,

  {insert name="get_time"}

  第二個: smarty_block

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

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

  模板寫法:{name}內(nèi)容{/name}

  寫成block插件:

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

  block.cacheless.php的內(nèi)容如下:

  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

  已經(jīng)緩存的:{$smarty.now}

  {cacheless}

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

  {/cacheless}

  4自定義緩存

  設置cache_handler_func使用自定義的函數(shù)處理緩存

  如:

  $smarty->cache_handler_func = "myCache";

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

  }

  該函數(shù)的一般是根椐$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來壓縮和解壓

【php-smarty模版引擎中的緩存應用】相關文章:

在Linux系統(tǒng)中如何清除squid的緩存10-20

PHP 中九大緩存技術總結11-01

PHP中9大緩存技術總結02-11

CPU緩存的作用11-24

PHP緩存技術11-17

java的緩存機制03-06

cpu緩存是什么09-11

php緩存技術經(jīng)典總結09-12

java的緩存機制簡介12-17

  • 相關推薦