Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6e4b8b

Browse files
Merge pull request#81 from TheDragonCode/3.x
Added the ability to work with tags without keys
2 parents5988fe6 +4646632 commitf6e4b8b

File tree

12 files changed

+139
-1
lines changed

12 files changed

+139
-1
lines changed

‎README.md‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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

433442
To 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).

‎src/Services/Cache.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public function forget(): static
109109
return$this;
110110
}
111111

112+
publicfunctionflush():static
113+
{
114+
$this->manager()->flush();
115+
116+
return$this;
117+
}
118+
112119
publicfunctionhas():bool
113120
{
114121
return$this->manager()->has($this->getKey());

‎src/Services/Storages/Disabled.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public function has(string $key): bool
3232
{
3333
returnfalse;
3434
}
35+
36+
publicfunctionflush():void {}
3537
}

‎src/Services/Storages/MainStore.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ public function has(string $key): bool
4949
{
5050
return Cache::has($key);
5151
}
52+
53+
publicfunctionflush():void
54+
{
55+
Cache::flush();
56+
}
5257
}

‎src/Services/Storages/TaggedStore.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function has(string $key): bool
6060
return$this->cache()->has($key);
6161
}
6262

63+
publicfunctionflush():void
64+
{
65+
$this->cache()->flush();
66+
}
67+
6368
protectedfunctioncache():TaggedCache
6469
{
6570
return Cache::tags($this->tags);

‎src/Support/CacheManager.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function doesntHave(string $key): bool
6666
return !$this->has($key);
6767
}
6868

69+
publicfunctionflush():void
70+
{
71+
$this->instance()->flush();
72+
}
73+
6974
protectedfunctioninstance():Store
7075
{
7176
returnmatch (true) {

‎tests/Cache/NotWhen/Simple/ArrayTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespaceTests\Cache\NotWhen\Simple;
66

7+
useDragonCode\Cache\Services\Cache;
78
useTests\Cache\NotWhen\Base;
89

910
class ArrayTestextends Base
@@ -51,6 +52,22 @@ public function testForget()
5152
$this->assertNull($this->cache()->get());
5253
}
5354

55+
publicfunctiontestFlush()
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
publicfunctiontestHas()
5572
{
5673
$this->assertFalse($this->cache()->has());

‎tests/Cache/NotWhen/Simple/FileTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespaceTests\Cache\NotWhen\Simple;
66

7+
useDragonCode\Cache\Services\Cache;
78
useTests\Cache\NotWhen\Base;
89

910
class FileTestextends Base
@@ -51,6 +52,22 @@ public function testForget()
5152
$this->assertNull($this->cache()->get());
5253
}
5354

55+
publicfunctiontestFlush()
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
publicfunctiontestHas()
5572
{
5673
$this->assertFalse($this->cache()->has());

‎tests/Cache/NotWhen/Simple/RedisTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespaceTests\Cache\NotWhen\Simple;
66

7+
useDragonCode\Cache\Services\Cache;
78
useIlluminate\Support\Facades\Auth;
89
useTests\Cache\NotWhen\Base;
910
useTests\Fixtures\Models\User;
@@ -73,6 +74,22 @@ public function testForget()
7374
$this->assertNull($this->cache(['cache'])->get());
7475
}
7576

77+
publicfunctiontestFlush()
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
publicfunctiontestHas()
7794
{
7895
$this->assertFalse($this->cache()->has());

‎tests/Cache/When/Simple/ArrayTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespaceTests\Cache\When\Simple;
66

7+
useDragonCode\Cache\Services\Cache;
78
useTests\Cache\When\Base;
89

910
class ArrayTestextends Base
@@ -61,6 +62,22 @@ public function testForget()
6162
$this->assertNull($this->cache()->get());
6263
}
6364

65+
publicfunctiontestFlush()
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
publicfunctiontestHas()
6582
{
6683
$this->assertFalse($this->cache()->has());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp