init
This commit is contained in:
53
app/common/behavior/ModuleCacheBehavior.php
Executable file
53
app/common/behavior/ModuleCacheBehavior.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
use think\Config;
|
||||
use think\Request;
|
||||
use think\Hook;
|
||||
use think\App;
|
||||
use think\Log;
|
||||
|
||||
class ModuleCacheBehavior {
|
||||
|
||||
protected static $moduleName = '';
|
||||
protected static $cachemoduleName;
|
||||
|
||||
/**
|
||||
* 系统配置读取并缓存
|
||||
*/
|
||||
public function appBegin(&$param) {
|
||||
switch ($param['type']) {
|
||||
case 'redirect': // 重定向跳转
|
||||
break;
|
||||
case 'module': // 模块/控制器/操作
|
||||
self::$moduleName = $param['module'][0];
|
||||
break;
|
||||
case 'controller': // 执行控制器操作
|
||||
break;
|
||||
case 'method': // 回调方法
|
||||
break;
|
||||
case 'function': // 闭包
|
||||
break;
|
||||
case 'response': // Response 实例
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('dispatch type not support');
|
||||
}
|
||||
self::$cachemoduleName = Config::get('html_cache_module', array());
|
||||
if (!empty(self::$cachemoduleName) && in_array(self::$moduleName, self::$cachemoduleName)) {
|
||||
// 监听 app_dispatch
|
||||
Hook::listen('app_cache_begin', $param);
|
||||
}
|
||||
App::$debug && Log::record("[ 模块缓存 ]:内容命中缓存处理HOOK");
|
||||
}
|
||||
|
||||
public function viewFilter(&$param) {
|
||||
if (!empty(self::$cachemoduleName) && in_array(self::$moduleName, self::$cachemoduleName)) {
|
||||
// 监听 app_cache_end
|
||||
Hook::listen('app_cache_end', $param);
|
||||
}
|
||||
App::$debug && Log::record("[ 模块缓存 ]:视图内容缓存处理HOOK");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user