thinkphp 删除所有缓存 Rumtime 以及 Html 静态缓存
<?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 静态缓存的更多相关文章
- ThinkPHP 3.2.3 数据缓存与静态缓存
ThinkPHP 3.2.3 中手册中数据缓存的地址是:http://www.kancloud.cn/manual/thinkphp/1835 静态缓存的地址是:http://www.kancloud ...
- thinkphp的静态缓存,数据缓存,快速缓存,查询缓存
// 静态缓存 // 'HTML_PATH' 缓存目录,这是个常量不是配置项,在入口文件中定义 // 'HTML_CACHE_ON' => true, // 开启静态缓存 'HTM ...
- Thinkphp路由配置和静态缓存规则【原创】
ThinkPHP框架对URL有一定的规范,所以如果你希望定制你的URL格式的话,就需要好好了解下内置的路由功能了,它能让你的URL变得更简洁和有文化. 首先我们在Common/config.php设置 ...
- Thinkphp 缓存和静态缓存局部缓存设置
1.S方法缓存设置 if(!$rows = S('indexBlog')){ //*$rows = S('indexBlog') $rows = D('blog')->select(); S(' ...
- thinkphp 静态缓存
要使用静态缓存功能,需要开启HTML_CACHE_ON参数,并且使用HTML_CACHE_RULES配置参数设置静态缓存规则文件 . 大理石构件厂家 虽然也可以在应用配置文件中定义静态缓存规则,但是建 ...
- thinkphp3.2开启静态缓存与缓存规则设置
网站的静态缓存对大访问量有很好的缓解作用,尤其对网站的大并发,可有效的缓解数据库的压力.在thinkphp中实现静态缓存很简单,thinkphp都已经封装好了直接调用即可. 静态缓存 首先设置 H ...
- ThinkPHP视图css和js加上版本号防止缓存
前台模块中,我的所有控制器都继承BaseController,虽然ThinkPHP中我们提供了两个配置项 'TMPL_CACHE_ON' => false,// 禁止模板编译缓存 'HTML_C ...
- thinkphp3.2----设置静态缓存
开启静态缓存后,页面刷新时获取的是静态页面,控制器增加输出内容时页面还是一样,除非超过缓存时间或html结构发生变化才重新生成页面缓存 1.定义静态缓存目录 define("HTML_PAT ...
- ThinkPHP第十九天(Ueditor高亮插件、扩展函数载入load、静态缓存)
1.使用Ueditor编辑器,插入代码后,显示的时候高亮显示,需要调用Ueditor中的第三方插件third-party中的SyntaxHighlighter 调用方法: 引入CSS和JS文件,并调用 ...
随机推荐
- Python 线程启动的四种方式
import threading,_thread def action(i): print(i **32) #带有状态的子类 class Mythread(threading.Thread): def ...
- [转载]netcore 使用surging框架发布到docker
demo运行在windows的docker中,系统是win10,所以需要先下载Docker for Windows,安装完毕后系统会重启,然后桌面上可以找到Docker for Windows的快捷图 ...
- 【33.20%】【LA 4320】【Ping pong】
[Description] N (3 ≤ N ≤ 20000) ping pong players live along a west-east street(consider the street ...
- 在Android实现client授权
OAuth对你的数据和服务正在变成实际上的同意訪问协议在没有分享用户password. 实际上全部的有名公司像Twitter.Google,Yahoo或者LinkedIn已经实现了它.在全部流行的程序 ...
- SqlBulkCopy 帮助类
using System;using System.Collections.Generic;using System.Configuration;using System.Data;using Sys ...
- android之ContentProvider和Uri具体解释
一.使用ContentProvider(内容提供者)共享数据 在android中ContentProvider的作用是对外共享数据,就是说能够通过ContentProvider把应用中的数据共享给其它 ...
- Spring学习笔记之六(数据源的配置)
1.前言 上一篇博客分析了,Spring中实现AOP的两种动态代理的机制,以下这篇博客.来解说一下Spring中的数据源的配置. 2.DAO支持的模板类 Spring提供了非常多关于Dao支持的模板 ...
- color2gray 的实现
无论是 rgb 还是 yuv 等三通道的颜色空间中的像素点,将其转换为单通道(pixel_depth=255.)中的像素,一般情况下都是采用的对原始颜色空间的 3 通道的像素点线性组合而得到单通道的像 ...
- 【物理】概念的理解 —— Phase(相位)
Phase is the position of a point in time (an instant) on a waveform cycle. 相位指的是波形周期中点在某一时刻的位置.Phase ...
- 微信小程序实现城市定位:获取当前所在的国家城市信息
微信小程序中,我们可以通过调用wx.getLocation()获取到设备当前的地理位置信息,这个信息是当前位置的经纬度.如果我们想获取当前位置是处于哪个国家,哪个城市等信息,该如何实现呢? 微信小程序 ...