本文整理汇总了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');
//.........这里部分代码省略.........