本文整理汇总了PHP中Nette\Database\Connection::setCacheStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::setCacheStorage方法的具体用法?PHP Connection::setCacheStorage怎么用?PHP Connection::setCacheStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Connection
的用法示例。
在下文中一共展示了Connection::setCacheStorage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createConnection
/**
* @return Nette\Database\Connection
* @throws Nette\InvalidArgumentException
*/
private function createConnection($name)
{
if (empty($this->configs[$name])) {
throw new Nette\InvalidArgumentException("Connection '{$name}' definition is missing in config!");
}
$config = $this->configs[$name];
$connection = new Nette\Database\Connection($config["dsn"], $config["user"], $config["password"]);
$connection->setCacheStorage($this->cacheStorage);
$connection->setDatabaseReflection($this->databaseReflection);
// Panels are not rendered on production but they are still logging!
// Preventing them from log in production will decrease memory usage!
if (!$this->isProduction) {
$connectionPanel = new Nette\Database\Diagnostics\ConnectionPanel();
Nette\Diagnostics\Debugger::$bar->addPanel($connectionPanel);
$connection->onQuery[] = $connectionPanel->logQuery;
}
return $connection;
}
示例2: Connection
<?php
use Nette\Caching\Storages\FileStorage;
use Nette\Database\Connection;
use Nette\Database\Reflection\DiscoveredReflection;
use Nette\Framework;
require_once __DIR__ . '/../../bootstrap.php';
Bootstrap::init();
Bootstrap::check(__DIR__);
$connection = new Connection(Bootstrap::$config['db']['driver'] . ':dbname=' . Bootstrap::$config['db']['dbname'], Bootstrap::$config['db']['user'], Bootstrap::$config['db']['password']);
$cacheStorage = Bootstrap::$config['cache'] ? new FileStorage(__DIR__ . '/temp') : NULL;
$connection->setCacheStorage($cacheStorage);
$connection->setDatabaseReflection(new DiscoveredReflection($cacheStorage));
$dao = $connection;
$startTime = -microtime(TRUE);
ob_start();
foreach ($dao->table('employees')->limit(Bootstrap::$config['limit']) as $employe) {
echo "{$employe->first_name} {$employe->last_name} ({$employe->emp_no})\n";
echo "Salaries:\n";
foreach ($employe->related('salaries') as $salary) {
echo $salary->salary, "\n";
}
echo "Departments:\n";
foreach ($employe->related('dept_emp') as $department) {
echo $department->dept->dept_name, "\n";
}
}
ob_end_clean();
$endTime = microtime(TRUE);
Bootstrap::result('NetteDatabase', '~2.0.0', $startTime, $endTime);