本文整理匯總了PHP中RedBeanPHP\Facade::useWriterCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP Facade::useWriterCache方法的具體用法?PHP Facade::useWriterCache怎麽用?PHP Facade::useWriterCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類RedBeanPHP\Facade
的用法示例。
在下文中一共展示了Facade::useWriterCache方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testCachingEffects
/**
* Test effects of cache.
*
* @return void
*/
public function testCachingEffects()
{
testpack('Testing WriteCache Query Writer Cache');
R::useWriterCache(FALSE);
R::debug(true, 1);
$logger = R::getDatabaseAdapter()->getDatabase()->getLogger();
$book = R::dispense('book')->setAttr('title', 'ABC');
$book->ownPage[] = R::dispense('page');
$id = R::store($book);
// Test load cache -- without
$logger->clear();
$book = R::load('book', $id);
$book = R::load('book', $id);
asrt(count($logger->grep('SELECT')), 2);
// With cache
R::useWriterCache(TRUE);
$logger->clear();
$book = R::load('book', $id);
$book = R::load('book', $id);
asrt(count($logger->grep('SELECT')), 1);
R::useWriterCache(FALSE);
// Test find cache
$logger->clear();
$book = R::find('book');
$book = R::find('book');
asrt(count($logger->grep('SELECT')), 2);
// With cache
R::getWriter()->setUseCache(TRUE);
$logger->clear();
$book = R::find('book');
$book = R::find('book');
asrt(count($logger->grep('SELECT')), 1);
R::getWriter()->setUseCache(FALSE);
// Test combinations
$logger->clear();
$book = R::findOne('book', ' id = ? ', array($id));
$book->ownPage;
R::batch('book', array($id));
$book = R::findOne('book', ' id = ? ', array($id));
$book->ownPage;
R::batch('book', array($id));
asrt(count($logger->grep('SELECT')), 6);
// With cache
R::getWriter()->setUseCache(TRUE);
$logger->clear();
R::batch('book', array($id));
$book = R::findOne('book', ' id = ? ', array($id));
$book->ownPage;
$book = R::findOne('book', ' id = ? ', array($id));
$book->ownPage;
asrt(count($logger->grep('SELECT')), 3);
R::getWriter()->setUseCache(FALSE);
// Test auto flush
$logger->clear();
$book = R::findOne('book');
$book->name = 'X';
R::store($book);
$book = R::findOne('book');
asrt(count($logger->grep('SELECT *')), 2);
// With cache
R::getWriter()->setUseCache(TRUE);
$logger->clear();
$book = R::findOne('book');
$book->name = 'Y';
// Will flush
R::store($book);
$book = R::findOne('book');
// Now the same, auto flushed
asrt(count($logger->grep('SELECT *')), 2);
R::getWriter()->setUseCache(FALSE);
// Test whether delete flushes as well (because uses selectRecord - might be a gotcha!)
R::store(R::dispense('garbage'));
$garbage = R::findOne('garbage');
$logger->clear();
$book = R::findOne('book');
R::trash($garbage);
$book = R::findOne('book');
asrt(count($logger->grep('SELECT *')), 2);
R::store(R::dispense('garbage'));
$garbage = R::findOne('garbage');
// With cache
R::getWriter()->setUseCache(TRUE);
$logger->clear();
$book = R::findOne('book');
R::trash($garbage);
$book = R::findOne('book');
// Now the same, auto flushed
asrt(count($logger->grep('SELECT *')), 2);
R::getWriter()->setUseCache(FALSE);
R::store(R::dispense('garbage'));
$garbage = R::findOne('garbage');
// With cache
R::getWriter()->setUseCache(TRUE);
$logger->clear();
$book = R::findOne('book');
//.........這裏部分代碼省略.........