一级日韩免费大片,亚洲一区二区三区高清,性欧美乱妇高清come,久久婷婷国产麻豆91天堂,亚洲av无码a片在线观看

php語(yǔ)言

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

時(shí)間:2025-03-30 02:27:51 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

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

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

  1,Smarty緩存的配置:

  $smarty->cache-dir="目錄名"; //創(chuàng )建緩存目錄名

  $smarty->caching=true; //開(kāi)啟緩存,為false的時(shí)候緩存無(wú)效

  $smarty->cache_lifetime=60; //緩存時(shí)間,單位是秒

  2,Smarty緩存的使用與清除

  $marty->display("cache.tpl",cache_id); //創(chuàng )建帶ID的緩存

  $marty->clear_all_cache(); //清楚所有緩存

  $marty->clear_cache("index.php"); //清楚index.php中的緩存

  $marty->clear_cache("index.php',cache_id); //清楚index.php中指定ID的緩存

  3,Smarty的局部緩存

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

  使用方法:例子

  index.php中,

  function insert_get_time(){

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

  }

  index.html中,

  {insert name="get_time"}

  第二個(gè): smarty_block

  定義一個(gè)block:smarty_block_name($params,$content, &$smarty){return $content;} //name表示區域名

  注冊block:$smarty->register_block('name', 'smarty_block_name', false); //第三參數false表示該區域不被緩存

  模板寫(xiě)法:{name}內容{/name}

  寫(xiě)成block插件:

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

  block.cacheless.php的內容如下:

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

  return $content;

  }

  ?>

  2) 編寫(xiě)程序及模板

  示例程序: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}

  沒(méi)有緩存的:{$smarty.now}

  {/cacheless}

  4自定義緩存

  設置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來(lái)判斷緩存當前操作:

  switch($action){

  case "read"://讀取緩存內容

  case "write"://寫(xiě)入緩存

  case "clear"://清空

  }

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

  如果需要,可使用gzcompress和gzuncompress來(lái)壓縮和解壓

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

在Linux系統中如何清除squid的緩存04-01

PHP中9大緩存技術(shù)總結02-11

PHP 中九大緩存技術(shù)總結05-23

CPU緩存的作用05-29

java的緩存機制07-29

PHP緩存技術(shù)05-03

java的緩存機制簡(jiǎn)介12-17

cpu緩存是什么06-03

php緩存技術(shù)經(jīng)典總結05-27

一级日韩免费大片,亚洲一区二区三区高清,性欧美乱妇高清come,久久婷婷国产麻豆91天堂,亚洲av无码a片在线观看