Skip to content

Commit 1d6b900

Browse files
committed
Fix adding tags on new cache flush events
1 parent bfeadb4 commit 1d6b900

8 files changed

+76
-67
lines changed

src/Illuminate/Cache/Events/CacheEvent.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,15 @@
22

33
namespace Illuminate\Cache\Events;
44

5-
abstract class CacheEvent
5+
abstract class CacheEvent extends TaggedCacheEvent
66
{
7-
/**
8-
* The name of the cache store.
9-
*
10-
* @var string|null
11-
*/
12-
public $storeName;
13-
147
/**
158
* The key of the event.
169
*
1710
* @var string
1811
*/
1912
public $key;
2013

21-
/**
22-
* The tags that were assigned to the key.
23-
*
24-
* @var array
25-
*/
26-
public $tags;
27-
2814
/**
2915
* Create a new event instance.
3016
*
@@ -34,21 +20,7 @@ abstract class CacheEvent
3420
*/
3521
public function __construct($storeName, $key, array $tags = [])
3622
{
37-
$this->storeName = $storeName;
23+
parent::__construct($storeName, $tags);
3824
$this->key = $key;
39-
$this->tags = $tags;
40-
}
41-
42-
/**
43-
* Set the tags for the cache event.
44-
*
45-
* @param array $tags
46-
* @return $this
47-
*/
48-
public function setTags($tags)
49-
{
50-
$this->tags = $tags;
51-
52-
return $this;
5325
}
5426
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Illuminate\Cache\Events;
4+
5+
class CacheFlushFailed extends TaggedCacheEvent
6+
{
7+
//
8+
}

src/Illuminate/Cache/Events/CacheFlushed.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@
22

33
namespace Illuminate\Cache\Events;
44

5-
class CacheFlushed
5+
class CacheFlushed extends TaggedCacheEvent
66
{
7-
/**
8-
* The name of the cache store.
9-
*
10-
* @var string|null
11-
*/
12-
public $storeName;
13-
14-
/**
15-
* Create a new event instance.
16-
*
17-
* @param string|null $storeName
18-
* @return void
19-
*/
20-
public function __construct($storeName)
21-
{
22-
$this->storeName = $storeName;
23-
}
7+
//
248
}

src/Illuminate/Cache/Events/CacheFlushing.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@
22

33
namespace Illuminate\Cache\Events;
44

5-
class CacheFlushing
5+
class CacheFlushing extends TaggedCacheEvent
66
{
7-
/**
8-
* The name of the cache store.
9-
*
10-
* @var string|null
11-
*/
12-
public $storeName;
13-
14-
/**
15-
* Create a new event instance.
16-
*
17-
* @param string|null $storeName
18-
* @return void
19-
*/
20-
public function __construct($storeName)
21-
{
22-
$this->storeName = $storeName;
23-
}
7+
//
248
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Illuminate\Cache\Events;
4+
5+
abstract class TaggedCacheEvent
6+
{
7+
/**
8+
* The name of the cache store.
9+
*
10+
* @var string|null
11+
*/
12+
public $storeName;
13+
14+
/**
15+
* The tags that were assigned to the key.
16+
*
17+
* @var array
18+
*/
19+
public $tags;
20+
21+
/**
22+
* Create a new tagged event instance.
23+
*
24+
* @param string|null $storeName
25+
* @param array $tags
26+
*/
27+
public function __construct($storeName, array $tags = [])
28+
{
29+
$this->storeName = $storeName;
30+
$this->tags = $tags;
31+
}
32+
33+
/**
34+
* Set the tags for the cache event.
35+
*
36+
* @param array $tags
37+
* @return $this
38+
*/
39+
public function setTags($tags)
40+
{
41+
$this->tags = $tags;
42+
43+
return $this;
44+
}
45+
}

src/Illuminate/Cache/RedisTaggedCache.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Illuminate\Cache;
44

5+
use Illuminate\Cache\Events\CacheFlushed;
6+
use Illuminate\Cache\Events\CacheFlushing;
7+
58
class RedisTaggedCache extends TaggedCache
69
{
710
/**
@@ -105,9 +108,13 @@ public function forever($key, $value)
105108
*/
106109
public function flush()
107110
{
111+
$this->event(new CacheFlushing($this->getName()));
112+
108113
$this->flushValues();
109114
$this->tags->flush();
110115

116+
$this->event(new CacheFlushed($this->getName()));
117+
111118
return true;
112119
}
113120

src/Illuminate/Cache/Repository.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Closure;
88
use DateTimeInterface;
99
use Illuminate\Cache\Events\CacheFlushed;
10+
use Illuminate\Cache\Events\CacheFlushFailed;
1011
use Illuminate\Cache\Events\CacheFlushing;
1112
use Illuminate\Cache\Events\CacheHit;
1213
use Illuminate\Cache\Events\CacheMissed;
@@ -584,6 +585,8 @@ public function clear(): bool
584585

585586
if ($result) {
586587
$this->event(new CacheFlushed($this->getName()));
588+
} else {
589+
$this->event(new CacheFlushFailed($this->getName()));
587590
}
588591

589592
return $result;

src/Illuminate/Cache/TaggedCache.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Cache;
44

5+
use Illuminate\Cache\Events\CacheFlushed;
6+
use Illuminate\Cache\Events\CacheFlushing;
57
use Illuminate\Contracts\Cache\Store;
68

79
class TaggedCache extends Repository
@@ -77,8 +79,12 @@ public function decrement($key, $value = 1)
7779
*/
7880
public function flush()
7981
{
82+
$this->event(new CacheFlushing($this->getName()));
83+
8084
$this->tags->reset();
8185

86+
$this->event(new CacheFlushed($this->getName()));
87+
8288
return true;
8389
}
8490

@@ -104,7 +110,7 @@ public function taggedItemKey($key)
104110
/**
105111
* Fire an event for this cache instance.
106112
*
107-
* @param \Illuminate\Cache\Events\CacheEvent $event
113+
* @param \Illuminate\Cache\Events\TaggedCacheEvent $event
108114
* @return void
109115
*/
110116
protected function event($event)

0 commit comments

Comments
 (0)