<?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;
}

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

thinkphp 删除所有缓存 Rumtime 以及 Html 静态缓存的更多相关文章

  1. ThinkPHP 3.2.3 数据缓存与静态缓存

    ThinkPHP 3.2.3 中手册中数据缓存的地址是:http://www.kancloud.cn/manual/thinkphp/1835 静态缓存的地址是:http://www.kancloud ...

  2. thinkphp的静态缓存,数据缓存,快速缓存,查询缓存

    // 静态缓存 // 'HTML_PATH' 缓存目录,这是个常量不是配置项,在入口文件中定义 // 'HTML_CACHE_ON'     =>    true, // 开启静态缓存 'HTM ...

  3. Thinkphp路由配置和静态缓存规则【原创】

    ThinkPHP框架对URL有一定的规范,所以如果你希望定制你的URL格式的话,就需要好好了解下内置的路由功能了,它能让你的URL变得更简洁和有文化. 首先我们在Common/config.php设置 ...

  4. Thinkphp 缓存和静态缓存局部缓存设置

    1.S方法缓存设置 if(!$rows = S('indexBlog')){ //*$rows = S('indexBlog') $rows = D('blog')->select(); S(' ...

  5. thinkphp 静态缓存

    要使用静态缓存功能,需要开启HTML_CACHE_ON参数,并且使用HTML_CACHE_RULES配置参数设置静态缓存规则文件 . 大理石构件厂家 虽然也可以在应用配置文件中定义静态缓存规则,但是建 ...

  6. thinkphp3.2开启静态缓存与缓存规则设置

    网站的静态缓存对大访问量有很好的缓解作用,尤其对网站的大并发,可有效的缓解数据库的压力.在thinkphp中实现静态缓存很简单,thinkphp都已经封装好了直接调用即可. 静态缓存   首先设置 H ...

  7. ThinkPHP视图css和js加上版本号防止缓存

    前台模块中,我的所有控制器都继承BaseController,虽然ThinkPHP中我们提供了两个配置项 'TMPL_CACHE_ON' => false,// 禁止模板编译缓存 'HTML_C ...

  8. thinkphp3.2----设置静态缓存

    开启静态缓存后,页面刷新时获取的是静态页面,控制器增加输出内容时页面还是一样,除非超过缓存时间或html结构发生变化才重新生成页面缓存 1.定义静态缓存目录 define("HTML_PAT ...

  9. ThinkPHP第十九天(Ueditor高亮插件、扩展函数载入load、静态缓存)

    1.使用Ueditor编辑器,插入代码后,显示的时候高亮显示,需要调用Ueditor中的第三方插件third-party中的SyntaxHighlighter 调用方法: 引入CSS和JS文件,并调用 ...

随机推荐

  1. Python IDLE如何清屏

    金gordon 原文 IDLE如何清屏 在学习和使用python的过程中,少不了要与Python IDLE打交道.但使用 Python IDLE 都会遇到一个常见而又懊恼的问题——要怎么清屏? 答案是 ...

  2. 【37.21%】【codeforces 721B】Passwords

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. MCMC:Gibbs 采样(matlab 实现)

    MCMC: The Gibbs Sampler 多元高斯分布的边缘概率和条件概率 Marginal and conditional distributions of multivariate norm ...

  4. 【poj2528】Mayor's posters

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59254   Accepted: 17167 Description The ...

  5. android生成分享长图而且加入全图水印

    尊重他人的劳动成果.转载请标明出处:http://blog.csdn.net/gengqiquan/article/details/65938021. 本文出自:[gengqiquan的博客] 领导近 ...

  6. [NPM] Run npm scripts when files change with onchange

    In this lesson we will look at how we can setup our npm scripts to execute when the file system has ...

  7. [javase学习笔记]-6.5 类类型參数与匿名对象

    这一节我们来说说类类型參数和匿名对象. 我们继续用之前的小汽车类吧 class Car { int num;//这是轮胎数属性 String color;//这是颜色属性 String brand;/ ...

  8. 关闭 You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法

    当我的MainActivity继承自v7包中的ActionBarActivity或者AppCompatActivity时,如果在style.xml文件中指定MainActivity所使用的样式如下: ...

  9. java线程池框架源代码分析

    相关类Executor,Executors.AbstractExecutorService.ExecutorService Executor:整个线程池运行者框架的顶层接口. 定义了一个execute ...

  10. AppStoreID--安装URL--应用更新URL--应用评分URL

    #define AppStoreID @"987353224" //应用安装URL #define AppStoreInstallURLFormat @"https:// ...