当前位置: 首页>>代码示例>>PHP>>正文


PHP Facade::useWriterCache方法代码示例

本文整理汇总了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');
//.........这里部分代码省略.........
开发者ID:skullyframework,项目名称:skully,代码行数:101,代码来源:Writecache.php


注:本文中的RedBeanPHP\Facade::useWriterCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。