Skip to content

Commit

Permalink
Merge branch 'cache-fix-15578' of https://github.com/aedart/framework
Browse files Browse the repository at this point in the history
…into aedart-cache-fix-15578
  • Loading branch information
taylorotwell committed Oct 12, 2016
2 parents 2e91104 + ddc3714 commit 96dfbff
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/ApcStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->apc->flush();
return $this->apc->flush();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/ApcWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public function delete($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->apcu ? apcu_clear_cache() : apc_clear_cache('user');
return $this->apcu ? apcu_clear_cache() : apc_clear_cache('user');
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/Cache/ArrayStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->storage = [];
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/DatabaseStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->table()->delete();
return (bool) $this->table()->delete();
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,19 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
if ($this->files->isDirectory($this->directory)) {
foreach ($this->files->directories($this->directory) as $directory) {
$this->files->deleteDirectory($directory);
if(!$this->files->deleteDirectory($directory)){
return false;
}
}
return true;
}
return false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/MemcachedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->memcached->flush();
return $this->memcached->flush();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/NullStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ public function forget($key)
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->connection()->flushdb();
return (bool) $this->connection()->flushdb();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Cache/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function forget($key);
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush();

Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/CacheApcStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ public function testForgetMethodProperlyCallsAPC()
$store = new Illuminate\Cache\ApcStore($apc);
$store->forget('foo');
}

public function testFlushesCached()
{
$apc = $this->getMockBuilder('Illuminate\Cache\ApcWrapper')->setMethods(['flush'])->getMock();
$apc->expects($this->once())->method('flush')->willReturn(true);
$store = new Illuminate\Cache\ApcStore($apc);
$result = $store->flush();
$this->assertTrue($result);
}
}
3 changes: 2 additions & 1 deletion tests/Cache/CacheArrayStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function testItemsCanBeFlushed()
$store = new ArrayStore;
$store->put('foo', 'bar', 10);
$store->put('baz', 'boom', 10);
$store->flush();
$result = $store->flush();
$this->assertTrue($result);
$this->assertNull($store->get('foo'));
$this->assertNull($store->get('baz'));
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Cache/CacheDatabaseStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public function testItemsMayBeFlushedFromCache()
$store = $this->getStore();
$table = m::mock('StdClass');
$store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table);
$table->shouldReceive('delete')->once();
$table->shouldReceive('delete')->once()->andReturn(2);

$store->flush();
$result = $store->flush();
$this->assertTrue($result);
}

public function testIncrementReturnsCorrectValues()
Expand Down
20 changes: 17 additions & 3 deletions tests/Cache/CacheFileStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ public function testFlushCleansDirectory()
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->will($this->returnValue(true));
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue(['foo']));
$files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'));
$files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'))->will($this->returnValue(true));

$store = new FileStore($files, __DIR__);
$store->flush();
$result = $store->flush();
$this->assertTrue($result, 'Flush failed');
}

public function testFlushFailsDirectoryClean()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->will($this->returnValue(true));
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue(['foo']));
$files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'))->will($this->returnValue(false));

$store = new FileStore($files, __DIR__);
$result = $store->flush();
$this->assertFalse($result, 'Flush should not have cleared directories');
}

public function testFlushIgnoreNonExistingDirectory()
Expand All @@ -132,7 +145,8 @@ public function testFlushIgnoreNonExistingDirectory()
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'--wrong'))->will($this->returnValue(false));

$store = new FileStore($files, __DIR__.'--wrong');
$store->flush();
$result = $store->flush();
$this->assertFalse($result, 'Flush should not clean directory');
}

protected function mockFilesystem()
Expand Down
13 changes: 13 additions & 0 deletions tests/Cache/CacheMemcachedStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ public function testForgetMethodProperlyCallsMemcache()
$store->forget('foo');
}

public function testFlushesCached()
{
if (! class_exists('Memcached')) {
$this->markTestSkipped('Memcached module not installed');
}

$memcache = $this->getMockBuilder('Memcached')->setMethods(['flush'])->getMock();
$memcache->expects($this->once())->method('flush')->willReturn(true);
$store = new Illuminate\Cache\MemcachedStore($memcache);
$result = $store->flush();
$this->assertTrue($result);
}

public function testGetAndSetPrefix()
{
if (! class_exists('Memcached')) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/CacheRedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public function testForgetMethodProperlyCallsRedis()
$redis->forget('foo');
}

public function testFlushesCached()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('flushdb')->once()->andReturn('ok');
$result = $redis->flush();
$this->assertTrue($result);
}

public function testGetAndSetPrefix()
{
$redis = $this->getRedis();
Expand Down

0 comments on commit 96dfbff

Please sign in to comment.