Permalink
Browse files

Merge branch 'feature/model-cacheforever' of https://github.com/semal…

…ead/framework into query-remember-forever
  • Loading branch information...
taylorotwell committed Nov 9, 2013
2 parents f3b8beb + ff13591 commit c6815845956e1cbd7039cefe67157ff0b3e8c557
Showing with 36 additions and 0 deletions.
  1. +17 −0 src/Illuminate/Database/Query/Builder.php
  2. +19 −0 tests/Database/DatabaseQueryBuilderTest.php
@@ -1033,6 +1033,19 @@ public function remember($minutes, $key = null)
return $this;
}
/**
* Indicate that the query results should be cached forever.
*
* @param string $key
* @return \Illuminate\Database\Query\Builder|static
*/
public function rememberForever($key = null)
{
list($this->cacheMinutes, $this->cacheKey) = array(0, $key);
return $this;
}
/**
* Execute a query for a single record by ID.
*
@@ -1126,6 +1139,10 @@ public function getCached($columns = array('*'))
$callback = $this->getCacheCallback($columns);
// Remember forever
if ($minutes == 0) return $cache->rememberForever($key, $callback);
// Remember for some minutes
return $cache->remember($key, $minutes, $callback);
}
@@ -65,6 +65,25 @@ public function testSelectWithCaching()
$this->assertEquals($query->get(), array('results'));
}
public function testSelectWithCachingForever()
{
$connection = m::mock('Illuminate\Database\ConnectionInterface');
$connection->shouldReceive('getName')->andReturn('connection_name');
$connection->shouldReceive('getCacheManager')->once()->andReturn($cache = m::mock('StdClass'));
$grammar = new Illuminate\Database\Query\Grammars\Grammar;
$processor = m::mock('Illuminate\Database\Query\Processors\Processor');
$builder = $this->getMock('Illuminate\Database\Query\Builder', array('getFresh'), array($connection, $grammar, $processor));
$builder->expects($this->once())->method('getFresh')->with($this->equalTo(array('*')))->will($this->returnValue(array('results')));
$query = $builder->select('*')->from('users')->where('email', 'foo@bar.com')->rememberForever();
$cache->shouldReceive('rememberForever')
->once()
->with($query->getCacheKey(), m::type('Closure'))
->andReturnUsing(function($key, $callback) { return $callback(); });
$this->assertEquals($query->get(), array('results'));
}
public function testBasicAlias()
{

0 comments on commit c681584

Please sign in to comment.