Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Cache: fix file store extending cache expiration time #15164

Merged
merged 1 commit into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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