Skip to content

Commit 43bd5bb

Browse files
feat(cache): add deleteMatching method definition in CacheInterface (#9809)
* feat(cache): add deleteMatching method definition in CacheInterface refs #7828 * docs(changelogs): add note about Cache interface change
1 parent 2609108 commit 43bd5bb

File tree

10 files changed

+17
-37
lines changed

10 files changed

+17
-37
lines changed

system/Cache/CacheInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public function save(string $key, $value, int $ttl = 60);
5151
*/
5252
public function delete(string $key);
5353

54+
/**
55+
* Deletes items from the cache store matching a given pattern.
56+
*
57+
* @param string $pattern Cache items glob-style pattern
58+
*
59+
* @return int Number of deleted items
60+
*/
61+
public function deleteMatching(string $pattern): int;
62+
5463
/**
5564
* Performs atomic incrementation of a raw stored value.
5665
*

system/Cache/Handlers/BaseHandler.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
use Closure;
1717
use CodeIgniter\Cache\CacheInterface;
18-
use CodeIgniter\Exceptions\BadMethodCallException;
1918
use CodeIgniter\Exceptions\InvalidArgumentException;
2019
use Config\Cache;
21-
use Exception;
2220

2321
/**
2422
* Base class for cache handling
@@ -98,18 +96,4 @@ public function remember(string $key, int $ttl, Closure $callback)
9896

9997
return $value;
10098
}
101-
102-
/**
103-
* Deletes items from the cache store matching a given pattern.
104-
*
105-
* @param string $pattern Cache items glob-style pattern
106-
*
107-
* @return int
108-
*
109-
* @throws Exception
110-
*/
111-
public function deleteMatching(string $pattern)
112-
{
113-
throw new BadMethodCallException('The deleteMatching method is not implemented.');
114-
}
11599
}

system/Cache/Handlers/DummyHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ public function delete(string $key)
6363

6464
/**
6565
* {@inheritDoc}
66-
*
67-
* @return int
6866
*/
69-
public function deleteMatching(string $pattern)
67+
public function deleteMatching(string $pattern): int
7068
{
7169
return 0;
7270
}

system/Cache/Handlers/FileHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,8 @@ public function delete(string $key)
131131

132132
/**
133133
* {@inheritDoc}
134-
*
135-
* @return int
136134
*/
137-
public function deleteMatching(string $pattern)
135+
public function deleteMatching(string $pattern): int
138136
{
139137
$deleted = 0;
140138

system/Cache/Handlers/MemcachedHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,8 @@ public function delete(string $key)
182182

183183
/**
184184
* {@inheritDoc}
185-
*
186-
* @return never
187185
*/
188-
public function deleteMatching(string $pattern)
186+
public function deleteMatching(string $pattern): never
189187
{
190188
throw new BadMethodCallException('The deleteMatching method is not implemented for Memcached. You must select File, Redis or Predis handlers to use it.');
191189
}

system/Cache/Handlers/PredisHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,8 @@ public function delete(string $key)
155155

156156
/**
157157
* {@inheritDoc}
158-
*
159-
* @return int
160158
*/
161-
public function deleteMatching(string $pattern)
159+
public function deleteMatching(string $pattern): int
162160
{
163161
$matchedKeys = [];
164162

system/Cache/Handlers/RedisHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ public function delete(string $key)
179179

180180
/**
181181
* {@inheritDoc}
182-
*
183-
* @return int
184182
*/
185-
public function deleteMatching(string $pattern)
183+
public function deleteMatching(string $pattern): int
186184
{
187185
/** @var list<string> $matchedKeys */
188186
$matchedKeys = [];

system/Cache/Handlers/WincacheHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ public function delete(string $key)
7575

7676
/**
7777
* {@inheritDoc}
78-
*
79-
* @return never
8078
*/
81-
public function deleteMatching(string $pattern)
79+
public function deleteMatching(string $pattern): never
8280
{
8381
throw new BadMethodCallException('The deleteMatching method is not implemented for Wincache. You must select File, Redis or Predis handlers to use it.');
8482
}

system/Test/Mock/MockCache.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ public function delete(string $key)
129129

130130
/**
131131
* Deletes items from the cache store matching a given pattern.
132-
*
133-
* @return int
134132
*/
135-
public function deleteMatching(string $pattern)
133+
public function deleteMatching(string $pattern): int
136134
{
137135
$count = 0;
138136

user_guide_src/source/changelogs/v4.7.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ across all insert/update operations.
4343
Interface Changes
4444
=================
4545

46+
- **Cache:** The ``CacheInterface`` now includes the ``deleteMatching()`` method. If you've implemented your own caching driver from scratch, you will need to provide an implementation for this method to ensure compatibility.
4647
- **Images:** The ``ImageHandlerInterface`` now includes a new method: ``clearMetadata()``. If you've implemented your own handler from scratch, you will need to provide an implementation for this method to ensure compatibility.
4748

4849
Method Signature Changes

0 commit comments

Comments
 (0)