Skip to content

Commit

Permalink
Cache: fix file store extending cache expiration time (#15164)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanpeto authored and taylorotwell committed Aug 31, 2016
1 parent cdabee1 commit d74b751
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ protected function getPayload($key)

// Next, we'll extract the number of minutes that are remaining for a cache
// so that we can properly retain the time for things like the increment
// operation that may be performed on the cache. We'll round this out.
$time = ceil(($expire - time()) / 60);
// operation that may be performed on the cache.
$time = ($expire - time()) / 60;

return compact('data', 'time');
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public function increment($key, $value = 1)

$int = ((int) $raw['data']) + $value;

$this->put($key, $int, (int) $raw['time']);
$this->put($key, $int, $raw['time']);

return $int;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ protected function path($key)
*/
protected function expiration($minutes)
{
$time = time() + ($minutes * 60);
$time = time() + (int) ($minutes * 60);

if ($minutes === 0 || $time > 9999999999) {
return 9999999999;
Expand Down
14 changes: 14 additions & 0 deletions tests/Cache/CacheFileStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ public function testForeversAreNotRemovedOnIncrement()
$this->assertEquals('Hello World', $store->get('foo'));
}

public function testIncrementDoesNotExtendCacheLife()
{
$files = $this->mockFilesystem();
$expiration = time() + 59;
$initialValue = $expiration.serialize(1);
$valueAfterIncrement = $expiration.serialize(2);
$store = new FileStore($files, __DIR__);
$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__.'/'.$cache_dir.'/'.$hash), $this->equalTo($valueAfterIncrement));
$store->increment('foo');
}

public function testRemoveDeletesFileDoesntExist()
{
$files = $this->mockFilesystem();
Expand Down

0 comments on commit d74b751

Please sign in to comment.