File tree Expand file tree Collapse file tree 12 files changed +139
-1
lines changed
Expand file tree Collapse file tree 12 files changed +139
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ Or manually update `require` block of `composer.json` and run `composer update`.
2121``` json
2222{
2323 "require" : {
24- "dragon-code/laravel-cache" : " ^3.9 "
24+ "dragon-code/laravel-cache" : " ^3.11 "
2525 }
2626}
2727```
@@ -201,6 +201,9 @@ $cache->doesntHave();
201201
202202$cache->forget();
203203// Will remove the key from the cache.
204+
205+ $cache->flush();
206+ // Clears keys or tags by value
204207```
205208
206209``` php
@@ -237,6 +240,9 @@ $cache->doesntHave();
237240
238241$cache->forget();
239242// Will remove the key from the cache.
243+
244+ $cache->flush();
245+ // Clears keys or tags by value
240246```
241247
242248#### Method Call Chain
@@ -428,6 +434,9 @@ $cache->doesntHave();
428434
429435$cache->forget();
430436// Will remove the key from the cache.
437+
438+ $cache->flush();
439+ // Clears keys or tags by value
431440```
432441
433442To retrieve a tagged cache item, pass the same ordered list of tags to the tags method and then call the get method with
@@ -451,6 +460,9 @@ $cache->tags('actor')->get();
451460
452461$cache->tags('author')->get();
453462// Returns `null`
463+
464+ $cache->tags('author')->flush();
465+ // Clears keys or tags by value
454466```
455467
456468> See the official Laravel [ documentation] ( https://laravel.com/docs/cache#accessing-tagged-cache-items ) .
Original file line number Diff line number Diff line change @@ -109,6 +109,13 @@ public function forget(): static
109109 return $ this ;
110110 }
111111
112+ public function flush (): static
113+ {
114+ $ this ->manager ()->flush ();
115+
116+ return $ this ;
117+ }
118+
112119 public function has (): bool
113120 {
114121 return $ this ->manager ()->has ($ this ->getKey ());
Original file line number Diff line number Diff line change @@ -32,4 +32,6 @@ public function has(string $key): bool
3232 {
3333 return false ;
3434 }
35+
36+ public function flush (): void {}
3537}
Original file line number Diff line number Diff line change @@ -49,4 +49,9 @@ public function has(string $key): bool
4949 {
5050 return Cache::has ($ key );
5151 }
52+
53+ public function flush (): void
54+ {
55+ Cache::flush ();
56+ }
5257}
Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ public function has(string $key): bool
6060 return $ this ->cache ()->has ($ key );
6161 }
6262
63+ public function flush (): void
64+ {
65+ $ this ->cache ()->flush ();
66+ }
67+
6368 protected function cache (): TaggedCache
6469 {
6570 return Cache::tags ($ this ->tags );
Original file line number Diff line number Diff line change @@ -66,6 +66,11 @@ public function doesntHave(string $key): bool
6666 return ! $ this ->has ($ key );
6767 }
6868
69+ public function flush (): void
70+ {
71+ $ this ->instance ()->flush ();
72+ }
73+
6974 protected function instance (): Store
7075 {
7176 return match (true ) {
Original file line number Diff line number Diff line change 44
55namespace Tests \Cache \NotWhen \Simple ;
66
7+ use DragonCode \Cache \Services \Cache ;
78use Tests \Cache \NotWhen \Base ;
89
910class ArrayTest extends Base
@@ -51,6 +52,22 @@ public function testForget()
5152 $ this ->assertNull ($ this ->cache ()->get ());
5253 }
5354
55+ public function testFlush ()
56+ {
57+ $ tags = Cache::make ()->tags ('foo ' , 'bar ' );
58+ $ cache = (clone $ tags )->key ('qwerty ' );
59+
60+ $ this ->assertNull ($ cache ->get ());
61+
62+ $ cache ->put ('asd ' );
63+
64+ $ this ->assertSame ('asd ' , $ cache ->get ());
65+
66+ $ tags ->flush ();
67+
68+ $ this ->assertNull ($ cache ->get ());
69+ }
70+
5471 public function testHas ()
5572 {
5673 $ this ->assertFalse ($ this ->cache ()->has ());
Original file line number Diff line number Diff line change 44
55namespace Tests \Cache \NotWhen \Simple ;
66
7+ use DragonCode \Cache \Services \Cache ;
78use Tests \Cache \NotWhen \Base ;
89
910class FileTest extends Base
@@ -51,6 +52,22 @@ public function testForget()
5152 $ this ->assertNull ($ this ->cache ()->get ());
5253 }
5354
55+ public function testFlush ()
56+ {
57+ $ tags = Cache::make ()->tags ('foo ' , 'bar ' );
58+ $ cache = (clone $ tags )->key ('qwerty ' );
59+
60+ $ this ->assertNull ($ cache ->get ());
61+
62+ $ cache ->put ('asd ' );
63+
64+ $ this ->assertSame ('asd ' , $ cache ->get ());
65+
66+ $ tags ->flush ();
67+
68+ $ this ->assertNull ($ cache ->get ());
69+ }
70+
5471 public function testHas ()
5572 {
5673 $ this ->assertFalse ($ this ->cache ()->has ());
Original file line number Diff line number Diff line change 44
55namespace Tests \Cache \NotWhen \Simple ;
66
7+ use DragonCode \Cache \Services \Cache ;
78use Illuminate \Support \Facades \Auth ;
89use Tests \Cache \NotWhen \Base ;
910use Tests \Fixtures \Models \User ;
@@ -73,6 +74,22 @@ public function testForget()
7374 $ this ->assertNull ($ this ->cache (['cache ' ])->get ());
7475 }
7576
77+ public function testFlush ()
78+ {
79+ $ tags = Cache::make ()->tags ('foo ' , 'bar ' );
80+ $ cache = (clone $ tags )->key ('qwerty ' );
81+
82+ $ this ->assertNull ($ cache ->get ());
83+
84+ $ cache ->put ('asd ' );
85+
86+ $ this ->assertSame ('asd ' , $ cache ->get ());
87+
88+ $ tags ->flush ();
89+
90+ $ this ->assertNull ($ cache ->get ());
91+ }
92+
7693 public function testHas ()
7794 {
7895 $ this ->assertFalse ($ this ->cache ()->has ());
Original file line number Diff line number Diff line change 44
55namespace Tests \Cache \When \Simple ;
66
7+ use DragonCode \Cache \Services \Cache ;
78use Tests \Cache \When \Base ;
89
910class ArrayTest extends Base
@@ -61,6 +62,22 @@ public function testForget()
6162 $ this ->assertNull ($ this ->cache ()->get ());
6263 }
6364
65+ public function testFlush ()
66+ {
67+ $ tags = Cache::make ()->tags ('foo ' , 'bar ' );
68+ $ cache = (clone $ tags )->key ('qwerty ' );
69+
70+ $ this ->assertNull ($ cache ->get ());
71+
72+ $ cache ->put ('asd ' );
73+
74+ $ this ->assertSame ('asd ' , $ cache ->get ());
75+
76+ $ tags ->flush ();
77+
78+ $ this ->assertNull ($ cache ->get ());
79+ }
80+
6481 public function testHas ()
6582 {
6683 $ this ->assertFalse ($ this ->cache ()->has ());
You can’t perform that action at this time.
0 commit comments