protected function setUp() { if (!extension_loaded("redis")) { $this->markTestSkipped("Redis没有安装,已跳过测试!"); } \think\Cache::connect(array('type' => 'redis', 'expire' => 2)); }
/** * 基境缓存类型 */ protected function setUp() { if (!extension_loaded("memcached") && !extension_loaded('memcache')) { $this->markTestSkipped("Memcached或Memcache没有安装,已跳过测试!"); } \think\Cache::connect(array('type' => 'memcached', 'expire' => 2)); }
/** * 基境缓存类型 */ protected function setUp() { if (!extension_loaded("apc")) { $this->markTestSkipped("APC没有安装,已跳过测试!"); } elseif ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) { $this->markTestSkipped("APC模块没有开启,已跳过测试!"); } \think\Cache::connect(array('type' => 'apc', 'expire' => 2)); }
/** * 缓存管理 * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 * @param mixed $value 缓存值 * @param mixed $options 缓存参数 * @return mixed */ function S($name, $value = '', $options = null) { if (is_array($options)) { // 缓存操作的同时初始化 \think\Cache::connect($options); } elseif (is_array($name)) { // 缓存初始化 return \think\Cache::connect($name); } if ('' === $value) { // 获取缓存 return \think\Cache::get($name); } elseif (is_null($value)) { // 删除缓存 return \think\Cache::rm($name); } else { // 缓存数据 if (is_array($options)) { $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间 } else { $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 } return \think\Cache::set($name, $value, $expire); } }
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: liu21st <*****@*****.**> // +---------------------------------------------------------------------- // $Id$ return ['url_route_on' => true, 'log' => ['type' => 'trace'], 'default_return_type' => 'json', 'system_error' => ['not_fonud_sign' => ['msg' => "缺少签名参数", 'code' => 1, 'type' => false], 'sign_error' => ['msg' => "签名错误", 'code' => 2, 'type' => false]], 'session' => ['prefix' => '', 'type' => '', 'auto_start' => true]]; $options = ['type' => 'Memcache', 'expire' => 0, 'prefix' => 'think', 'host' => '127.0.0.1', 'port' => '11211']; \think\Cache::connect($options);
/** * 缓存管理 * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 * @param mixed $value 缓存值 * @param mixed $options 缓存参数 * @param string $tag 缓存标签 * @return mixed */ function cache($name, $value = '', $options = null, $tag = null) { if (is_array($options)) { // 缓存操作的同时初始化 Cache::connect($options); } elseif (is_array($name)) { // 缓存初始化 return Cache::connect($name); } if ('' === $value) { // 获取缓存 return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name); } elseif (is_null($value)) { // 删除缓存 return Cache::rm($name); } else { // 缓存数据 if (is_array($options)) { $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间 } else { $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 } if (is_null($tag)) { return Cache::set($name, $value, $expire); } else { return Cache::tag($tag)->set($name, $value, $expire); } } }
/** * 清空缓存测试 * @return mixed * @access public */ public function testClear() { $cache = Cache::connect(['type' => 'Test']); $this->assertTrue($cache->clear()); }
/** * 基境缓存类型 */ protected function setUp() { \think\Cache::connect(array('type' => 'apc', 'expire' => 2)); }
/** * 基境缓存类型 */ protected function setUp() { //数据库缓存测试因为缺少数据库单元测试所以暂时跳过 $this->markTestSkipped("暂时跳过测试。"); \think\Cache::connect(array('type' => 'db', 'expire' => 2)); }
/** * 清空所有缓存 * @return bool */ public function clearCacheAll() { $caches = array(RUNTIME_PATH . "HTML", RUNTIME_PATH . "Cache", RUNTIME_PATH . "Data", RUNTIME_PATH . "Temp", RUNTIME_PATH . "~runtime.php"); foreach ($caches as $value) { $this->clearCache($value); } $Cache = new Cache(); $caches = $Cache->connect(); $caches->clear(); return true; }
/** * 执行应用程序 * @access public * @return void */ public static function run($config) { // 日志初始化 Log::init($config['log']); // 缓存初始化 Cache::connect($config['cache']); // 加载框架底层语言包 if (is_file(THINK_PATH . 'Lang/' . strtolower($config['default_lang']) . EXT)) { Lang::set(include THINK_PATH . 'Lang/' . strtolower($config['default_lang']) . EXT); } if (is_file(APP_PATH . 'build.php')) { // 自动化创建脚本 Create::build(include APP_PATH . 'build.php'); } // 监听app_init Hook::listen('app_init'); // 初始化公共模块 define('COMMON_PATH', APP_PATH . $config['common_module'] . '/'); self::initModule(COMMON_PATH, $config); // 启动session if (!IS_CLI) { Session::init($config['session']); } // 应用URL调度 self::dispatch($config); // 监听app_run Hook::listen('app_run'); // 执行操作 if (!preg_match('/^[A-Za-z](\\/|\\w)*$/', CONTROLLER_NAME)) { // 安全检测 $instance = false; } elseif ($config['action_bind_class']) { // 操作绑定到类:模块\controller\控制器\操作 if (is_dir(MODULE_PATH . CONTROLLER_LAYER . '/' . CONTROLLER_NAME)) { $namespace = MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . CONTROLLER_NAME . '\\'; } else { // 空控制器 $namespace = MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\empty\\'; } $actionName = strtolower(ACTION_NAME); if (class_exists($namespace . $actionName)) { $class = $namespace . $actionName; } elseif (class_exists($namespace . '_empty')) { // 空操作 $class = $namespace . '_empty'; } else { throw new Exception('_ERROR_ACTION_:' . ACTION_NAME); } $instance = new $class(); // 操作绑定到类后 固定执行run入口 $action = 'run'; } else { $instance = Loader::controller(CONTROLLER_NAME); // 获取当前操作名 $action = ACTION_NAME . $config['action_suffix']; } if (!$instance) { throw new Exception('[ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(CONTROLLER_NAME, 1) . ' ] not exists'); } try { // 操作方法开始监听 $call = [$instance, $action]; Hook::listen('action_begin', $call); if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) { // 非法操作 throw new \ReflectionException(); } //执行当前操作 $method = new \ReflectionMethod($instance, $action); if ($method->isPublic()) { // URL参数绑定检测 if ($config['url_params_bind'] && $method->getNumberOfParameters() > 0) { switch ($_SERVER['REQUEST_METHOD']) { case 'POST': $vars = array_merge($_GET, $_POST); break; case 'PUT': parse_str(file_get_contents('php://input'), $vars); break; default: $vars = $_GET; } $params = $method->getParameters(); $paramsBindType = $config['url_parmas_bind_type']; foreach ($params as $param) { $name = $param->getName(); if (1 == $paramsBindType && !empty($vars)) { $args[] = array_shift($vars); } if (0 == $paramsBindType && isset($vars[$name])) { $args[] = $vars[$name]; } elseif ($param->isDefaultValueAvailable()) { $args[] = $param->getDefaultValue(); } else { throw new Exception('_PARAM_ERROR_:' . $name); } } array_walk_recursive($args, 'Input::filterExp'); $data = $method->invokeArgs($instance, $args); } else { $data = $method->invoke($instance); } // 操作方法执行完成监听 Hook::listen('action_end', $call); if (IS_API) { // API接口返回数据 self::returnData($data, $config['default_ajax_return']); } } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); } } catch (\ReflectionException $e) { // 操作不存在 if (method_exists($instance, '_empty')) { $method = new \ReflectionMethod($instance, '_empty'); $method->invokeArgs($instance, [$action, '']); } else { throw new Exception('[ ' . (new \ReflectionClass($instance))->getName() . ':' . $action . ' ] not exists ', 404); } } // 监听app_end Hook::listen('app_end'); return; }
/** * 基境缓存类型 */ protected function setUp() { \think\Cache::connect(['type' => 'File', 'path' => CACHE_PATH]); }
/** * 基境缓存类型 */ protected function setUp() { \think\Cache::connect(array('type' => 'eaccelerator', 'expire' => 2)); }
/** * 清空所有缓存 * @return bool */ public function clearCacheAll() { if (C('DATA_CACHE_TYPE') == 'File') { $caches = array(RUNTIME_PATH . "HTML", RUNTIME_PATH . "Cache", RUNTIME_PATH . "Data", RUNTIME_PATH . "Temp", RUNTIME_PATH . "~runtime.php"); foreach ($caches as $value) { $this->clearCache($value); } } else { $Cache = new Cache(); $caches = $Cache->connect(); $caches->clear(); } return true; }
static function clearAll() { $Cache = new Cache(); $caches = $Cache->connect(); $caches->clear(); }
protected function getCacheInstance() { return Cache::connect(['type' => 'Lite', 'path' => CACHE_PATH]); }