<?php
/**
* This is not a free software, All Copyright @F.Z.B
* Date: 14-8-12 下午4:08
* File: CacheController.class.php
* Author: default.fu@foxmail.com
*/ namespace Api\Controller; class CacheController extends InitController
{
public function cleanAll()
{
$this->totalSize = 0;
$this->totalFile = 0;
$GLOBALS['arrFiles'] = $GLOBALS['arrDirs'] = array(); $this->dropDir(HTML_PATH);
$this->dropDir(RUNTIME_PATH); //ThinkPHP 3.2 不会自己主动生成Html缓存文件夹
if (!is_dir(HTML_PATH)) mkdir(HTML_PATH); $data = array(
'totalFile' => $this->totalFile,
'totalSize' => byte_format($this->totalSize),
'arrFiles' => $GLOBALS['arrFiles'],
'arrDirs' => $GLOBALS['arrDirs'],
'result' => 1,
'reqtime' => date('Y-m-d H:i:s'),
); $returnType = I('type') == 'JSON' ? 'JSON' : 'JSONP';
$this->ajaxReturn($data, $returnType); } public function dropDir($path = '')
{
$path = trimRepeatSlash($path);
if (is_file($path)) {
$this->totalSize += filesize($path);
$this->totalFile++;
$GLOBALS['arrFiles'][] = $path;
unlink($path); } else if (is_dir($path)) {
if (($dir = opendir($path)) !== false) {
while (($file = readdir($dir)) !== false) {
if ($file != '.' && $file != '..') {
$this->dropDir($path . '/' . $file);
}
} $GLOBALS['arrDirs'][] = $path;
rmdir($path);
}
}
}
} #thinkphp3.2.x设置缓存开启#
<?php
return array(
//'配置项'=>'配置值'
'LAYOUT_ON' => true,
'HTML_CACHE_ON' => strpos($_SERVER['HTTP_HOST'], '.') !== false, // 开启静态缓存 默觉得 true 本地不开启
'HTML_CACHE_TIME' => 3600, // 全局静态缓存有效期(秒)
'HTML_FILE_SUFFIX' => '.shtml', // 设置静态缓存文件后缀
'HTML_CACHE_RULES' => array(
'*' => array('{:module}/{:controller}/{:action}/{$_SERVER.REQUEST_URI|md5}', 3600, 'trimSW'),
)
);

#trimSW函数#

/**
* @author default.fu@foxmail.com
* @description 去除 空格 和非\w 字符串,用于cache 配置
*
* @param $str
* @param string $emptyValue
*
* @return mixed|string
*/
function trimSW($str, $emptyValue = '_empty_')
{
$str = preg_replace('/([^\w\/]+)/', '-', $str);
if (empty($str)) {
$str = $emptyValue;
} return $str;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

最新文章

  1. 如何给frame标签的src属性以及a标签的href属性自动设值
  2. Object.create
  3. BackgroundWorker控件
  4. Elasticsearch--配置文件
  5. Promise 学习笔记
  6. uboot 网络不通问题解决一例1
  7. 镜面电火花EDM加工技术资料,模具行业的人应该好好看看!
  8. Objective-C--Runtime机制
  9. POJ 1742 Coins(多重背包) DP
  10. Android] Android XML解析学习——方式比较
  11. app与后台交互之间的几种安全认证机制
  12. vim 命令大全 / vi 命令大全
  13. mongodb备份恢复,数据导入导出
  14. mysql 免安装与 忘记root密码 密码过期
  15. oracle基础语句练习
  16. linux服务端日志中截取自己所需要的部分
  17. 数据库部分(MySql)_3
  18. layui 弹窗的iframe 父子界面相互传值
  19. angular笔记_1
  20. 自闭的D7

热门文章

  1. 微信测试号开发之九 微信网页授权:页面获取用户openid
  2. python 设计模式之 单例模式
  3. ios开发总结:Utils常用方法等收集,添加扩展类,工具类方法,拥有很多方便快捷功能(不断更新中。。。)
  4. 【codeforces 755B】PolandBall and Game
  5. hdu 1292 &amp;quot;下沙野骆驼&amp;quot;ACM夏令营 (递推)
  6. Thermally driven workload scheduling in a heterogeneous multi-processor system on a chip
  7. Indy10 控件的使用(2)TidTCpServer组件学习
  8. MIPS重返硅谷 放眼AI未来
  9. Python 第三方库 cp27、cp35 等文件名的含义
  10. 数据库版本管理工具Flyway——基础篇