Skip to content

Commit

Permalink
refactoring cache
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 1, 2017
1 parent 9521cea commit f3aaf57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FileStore implements Store
public function __construct(Filesystem $files, $directory)
{
$this->files = $files;
$this->directory = $directory.'/data';
$this->directory = $directory;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/CacheDatabaseStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testEncryptedValueIsUpdatedWhenInsertThrowsException()
$table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => 'bar', 'expiration' => 61])->andReturnUsing(function () {
throw new Exception;
});
$table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table);
$table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table);
$table->shouldReceive('update')->once()->with(['value' => 'bar', 'expiration' => 61]);

$store->put('foo', 'bar', 1);
Expand Down
24 changes: 12 additions & 12 deletions tests/Cache/CacheFileStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testPutCreatesMissingDirectories()
{
$files = $this->mockFilesystem();
$hash = sha1('foo');
$full_dir = __DIR__.'/data/'.substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$full_dir = __DIR__.'/'.substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('makeDirectory')->with($this->equalTo($full_dir), $this->equalTo(0777), $this->equalTo(true));
$files->expects($this->once())->method('put')->with($this->equalTo($full_dir.'/'.$hash));
$store = new FileStore($files, __DIR__);
Expand Down Expand Up @@ -54,7 +54,7 @@ public function testStoreItemProperlyStoresValues()
$contents = '1111111111'.serialize('Hello World');
$hash = sha1('foo');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/data/'.$cache_dir.'/'.$hash), $this->equalTo($contents));
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash), $this->equalTo($contents));
$store->put('foo', 'Hello World', 10);
}

Expand All @@ -64,7 +64,7 @@ public function testForeversAreStoredWithHighTimestamp()
$contents = '9999999999'.serialize('Hello World');
$hash = sha1('foo');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/data/'.$cache_dir.'/'.$hash), $this->equalTo($contents));
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash), $this->equalTo($contents));
$store = new FileStore($files, __DIR__);
$store->forever('foo', 'Hello World', 10);
}
Expand All @@ -90,7 +90,7 @@ public function testIncrementDoesNotExtendCacheLife()
$files->expects($this->once())->method('get')->will($this->returnValue($initialValue));
$hash = sha1('foo');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/data/'.$cache_dir.'/'.$hash), $this->equalTo($valueAfterIncrement));
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash), $this->equalTo($valueAfterIncrement));
$store->increment('foo');
}

Expand All @@ -99,7 +99,7 @@ public function testRemoveDeletesFileDoesntExist()
$files = $this->mockFilesystem();
$hash = sha1('foobull');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/data/'.$cache_dir.'/'.$hash))->will($this->returnValue(false));
$files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash))->will($this->returnValue(false));
$store = new FileStore($files, __DIR__);
$store->forget('foobull');
}
Expand All @@ -111,16 +111,16 @@ public function testRemoveDeletesFile()
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$store = new FileStore($files, __DIR__);
$store->put('foobar', 'Hello Baby', 10);
$files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/data/'.$cache_dir.'/'.$hash))->will($this->returnValue(true));
$files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/data/'.$cache_dir.'/'.$hash));
$files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash))->will($this->returnValue(true));
$files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash));
$store->forget('foobar');
}

public function testFlushCleansDirectory()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'/data'))->will($this->returnValue(true));
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__.'/data'))->will($this->returnValue(['foo']));
$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(true));

$store = new FileStore($files, __DIR__);
Expand All @@ -131,8 +131,8 @@ public function testFlushCleansDirectory()
public function testFlushFailsDirectoryClean()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'/data'))->will($this->returnValue(true));
$files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__.'/data'))->will($this->returnValue(['foo']));
$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__);
Expand All @@ -143,7 +143,7 @@ public function testFlushFailsDirectoryClean()
public function testFlushIgnoreNonExistingDirectory()
{
$files = $this->mockFilesystem();
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'--wrong/data'))->will($this->returnValue(false));
$files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'--wrong'))->will($this->returnValue(false));

$store = new FileStore($files, __DIR__.'--wrong');
$result = $store->flush();
Expand Down

0 comments on commit f3aaf57

Please sign in to comment.