function testCache() { $dir = __DIR__ . '/../cache'; $cache = new File(['directory' => $dir]); $users = ['Masoud', 'Alireza']; $cache->write('users', $users); $this->assertCount(1, $cache->stats()); $this->assertTrue($cache->contains('users')); $this->assertEquals($users, $cache->read('users')); $this->assertFalse($cache->expired('users', 1)); $i = 0; $posts = ['Post 1', 'Post 2']; for ($j = 0; $j < 10; $j++) { $result = $cache->remember('posts', function () use(&$i, $posts) { $i++; return $posts; }, 10); } $this->assertEquals(1, $i); $this->assertEquals($posts, $result); $this->assertEquals($posts, $cache->read('posts')); $this->assertCount(2, $cache->stats()); $cache->delete('users'); $this->assertFalse($cache->contains('users')); $this->assertTrue($cache->contains('posts')); $cache->deleteAll(); $this->assertCount(0, $cache->stats()); @unlink($dir); }
/** * 批量操作 * */ public function actionBatch() { if (XUtils::method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif (XUtils::method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; is_array($ids) && ($ids = implode(',', $ids)); } else { XUtils::message('errorBack', '只支持POST,GET数据'); } empty($ids) && XUtils::message('error', '未选择记录'); switch ($command) { case 'delete': parent::_acl('file_delete'); $cityModel = new File(); $cityModel->deleteAll('id IN(' . $ids . ')'); AdminLogger::_create(array('catalog' => 'delete', 'intro' => '删除文件,ID:' . $ids)); parent::_delete(new File(), $ids, array('index')); break; default: throw new CHttpException(404, '错误的操作类型:' . $command); break; } }