原理,利用php的类可以根据类对象直接列出全部的本类中method能力,配合在缓存中存放缓存名称(给人看的,如果你不想只能看到方法名);
把所有的缓存更新方法写到一个类中;
保存cache时使用如下格式
<?php
return array(
'name'=>'xxx的缓存',
'time'=>缓存生成时间,
'life_sec'=>缓存过期(秒,-1无过期,0无缓存,其它)
'data'=>缓存数据反编码成php代码
);
管理php编写
case 'flush'://更新对应的缓存
if (empty($method)){
alert('方法参数有误');
}
if (!method_exists ( $cache_obj, $method)){
alert($method. '方法不存在');
}
$cache_obj->$method();
alert('已更新缓存为现在最新数据', 'cache.php?action=view');
break;
case 'view'://从缓存类中,取出所有的缓存名称/生成时间/生成方法
$methods = get_class_methods(get_class($cache_obj));
foreach($methods as $method){
$cache_return = importCache($method, false);
$data[] = '<a href="cache.php?action=flush&method=' .$method. '">更新 ' .$cache_return['name']. '</a>';
$data[] = '生成时间:' .date_ymdt($cache_return['time']);
}
$smarty->assign('title','缓存更新时间');
$smarty->assign('data',$data);
$smarty->display('cache.html');
break;
生成的管理列表会是
更新 xxx缓存 生成时间:xxxxxx
点击更新 xxx缓存即可再次更新缓存
而无需写一个缓存,再写一次更新的调用










