zoukankan      html  css  js  c++  java
  • 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 ApiController;
    
    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;
    }

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

  • 相关阅读:
    Win8系统 Python安装
    一些安卓开源框架整理
    Android 媒体键监听以及模拟媒体键盘的实现 demo
    android View 自动 GONE 问题
    Android 定时器TimerTask 简单使用
    关于Android studio 相对 eclipse 优点
    Java序列化与反序列化
    android shape的使用 边框
    Android Studio 修改 包名 package name
    Android WebView Long Press长按保存图片到手机
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4635485.html
Copyright © 2011-2022 走看看