<?php
/**
 * 缓存管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class CacheController extends BaseController {
    public function index() {$this->display();}
    public function clearCache(){
    	set_time_limit(0);
        $i = intval(I('id'));
        if (!$i) {
            $this->error('操作失败');
        } else {
			$dir = new \Common\Vendor\Dir;
            $cache = new \Think\Cache;
            $prefix='';
            switch($i){
                case 1:
                    //更新全站缓存
                    is_dir(CACHE_PATH) && $dir->delDir(CACHE_PATH);
                    is_dir(DATA_PATH) && $dir->delDir(DATA_PATH,$prefix);
                    $cache->getInstance()->clear();
                    is_dir(RUNTIME_PATH.'statics/') && $dir->del(RUNTIME_PATH.'statics/');
                    break;
                case 2://后台模版缓存
                    is_dir(CACHE_PATH.'Admin/') && $dir->del(CACHE_PATH.'Admin/');
                    break;
                case 3://前台模版缓存
                    is_dir(CACHE_PATH.'Home/') && $dir->del(CACHE_PATH.'Home/');
                    break;
                case 4://DATA数据缓存
                    is_dir(DATA_PATH) && $dir->delDir(DATA_PATH,$prefix);
                    break;
                case 5://TEMP数据缓存
                    $cache->getInstance()->clear();
                    break;
                case 6://脚本样式缓存
                    is_dir(RUNTIME_PATH.'statics/') && $dir->del(RUNTIME_PATH.'statics/');
                    break;
                case 7://数据缓存
                    is_dir(DATA_PATH.'_fields/') && $dir->del(DATA_PATH.'_fields/');
                    break;
                case 8://缩略图
                    $thumbdir= './'.C('UPLOAD_PATH').'thumb/';
                    is_dir($thumbdir) && $dir->del($thumbdir);
                    break;
                default:break;
            }
			$runtime_file =$prefix? RUNTIME_PATH .$prefix.'~runtime.php':RUNTIME_PATH .'common~runtime.php';            
			is_file($runtime_file) && @unlink($runtime_file);
            $this->success('更新完成', U('Cache/index'));
        }
    }

}

?>