Skip to content
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
6 changes: 3 additions & 3 deletions src/Illuminate/Cache/Events/KeyWritten.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class KeyWritten extends CacheEvent
/**
* The number of minutes the key should be valid.
*
* @var int
* @var int|null
*/
public $minutes;

Expand All @@ -23,11 +23,11 @@ class KeyWritten extends CacheEvent
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @param int|null $minutes
* @param array $tags
* @return void
*/
public function __construct($key, $value, $minutes, $tags = [])
public function __construct($key, $value, $minutes = null, $tags = [])
{
parent::__construct($key, $tags);

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ public function decrement($key, $value = 1)
* Store an item in the cache indefinitely.
*
* @param string $key
* @param mixed $value
* @param mixed $value
* @return bool
*/
public function forever($key, $value)
{
$result = $this->store->forever($this->itemKey($key), $value);

if ($result) {
$this->event(new KeyWritten($key, $value, 0));
$this->event(new KeyWritten($key, $value));
}

return $result;
Expand Down
20 changes: 10 additions & 10 deletions tests/Cache/CacheEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public function testPutTriggersEvents()
$dispatcher = $this->getDispatcher();
$repository = $this->getRepository($dispatcher);

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99]));
$repository->put('foo', 'bar', 99);

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99, 'tags' => ['taylor']]));
$repository->tags('taylor')->put('foo', 'bar', 99);
}

Expand All @@ -93,11 +93,11 @@ public function testAddTriggersEvents()
$repository = $this->getRepository($dispatcher);

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99]));
$this->assertTrue($repository->add('foo', 'bar', 99));

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99, 'tags' => ['taylor']]));
$this->assertTrue($repository->tags('taylor')->add('foo', 'bar', 99));
}

Expand All @@ -106,10 +106,10 @@ public function testForeverTriggersEvents()
$dispatcher = $this->getDispatcher();
$repository = $this->getRepository($dispatcher);

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null]));
$repository->forever('foo', 'bar');

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null, 'tags' => ['taylor']]));
$repository->tags('taylor')->forever('foo', 'bar');
}

Expand All @@ -119,13 +119,13 @@ public function testRememberTriggersEvents()
$repository = $this->getRepository($dispatcher);

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99]));
$this->assertEquals('bar', $repository->remember('foo', 99, function () {
return 'bar';
}));

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99, 'tags' => ['taylor']]));
$this->assertEquals('bar', $repository->tags('taylor')->remember('foo', 99, function () {
return 'bar';
}));
Expand All @@ -137,13 +137,13 @@ public function testRememberForeverTriggersEvents()
$repository = $this->getRepository($dispatcher);

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null]));
$this->assertEquals('bar', $repository->rememberForever('foo', function () {
return 'bar';
}));

$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null, 'tags' => ['taylor']]));
$this->assertEquals('bar', $repository->tags('taylor')->rememberForever('foo', function () {
return 'bar';
}));
Expand Down