聘我网

新概念招聘3.0

问一个smarty缓存问题

vote up0vote downstar

Smarty配置:

include_once("Smarty.class.php");    
$smarty = new smarty();
$smarty->template_dir = './templates/';
$smarty->compile_dir  = './templates_c/';
$smarty->config_dir   = './config/';
$smarty->cache_dir    = './cache/';
$smarty->caching      = true;
$smarty->cache_lifetime= 60;
$smarty->left_delimiter = "{";
$smarty->right_delimiter = "}";

//****************** 这个是我的smarty类的调用

include("smarty_inc.php");

// $name="php中文网站";
$value=array(
    'a'=>'php学习1001',
    'b'=>'java',
    'c'=>'c++',
    );
$smarty->assign('name',$value);
$smarty->display("index.html");

这个是我的index.php的文件

<body>
{foreach from=$name item=a}
 {$a}<br >
 {/foreach}

</body>

这个是我的index.html 文件 可是我出来cache文件是

132
a:4:{s:8:"template";a:1:{s:10:"index.html";b:1;}s:9:"timestamp";i:1256260771;s:7:"expires";i:1256260831;s:13:"cache_serials";a:0:{}}<! 
php学习1001<br >
  java<br >
  c++<br >

</body>
</html>

如果我改动php学习100 按理cache文件出现的

132
a:4:{s:8:"template";a:1:{s:10:"index.html";b:1;}s:9:"timestamp";i:1256260771;s:7:"expires";i:1256260831;s:13:"cache_serials";a:0:{}}<! 

这串代码应该出现在php学习100的位置啊,我的代码或者配置哪里错了,希望指点一下

 
改动后生成的cache文件没贴全吧? - Shore 2009-10-22, 23:12

1 个答复

vote up1vote downcheck

没太看懂你的意思,

$smarty->cache_lifetime= 60;

这条语句使得你在60秒之内修改index.php无效。

可能你需要聊几下这两个参数:

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

第一个参数是当模板有修改时重新生成cache 第二个参数是强制重新生成cache,相当于没有cache,是本地调试时使用的。

更新 至于那段输出,你运行一下这个就知道了:

<?php
$serialized = 'a:4:{s:8:"template";a:1:{s:10:"index.html";b:1;}s:9:"timestamp";i:1256373019;s:7:"expires";i:1256373079;s:13:"cache_serials";a:0:{}}';
$unserialized = unserialize($serialized);
print_r($unserialized);

输出:

Array
(
[template] => Array
    (
        [index.html] => 1
    )

[timestamp] => 1256373019
[expires] => 1256373079
[cache_serials] => Array
    (
    )

)
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.