From 15be8d508c6ce8200b2d3e9be36bacdbceb55fb4 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Sun, 23 Nov 2025 17:26:44 +0000 Subject: [PATCH 1/2] feat(cache): add deleteMatching method definition in CacheInterface refs #7828 --- system/Cache/CacheInterface.php | 9 +++++++++ system/Cache/Handlers/BaseHandler.php | 16 ---------------- system/Cache/Handlers/DummyHandler.php | 4 +--- system/Cache/Handlers/FileHandler.php | 4 +--- system/Cache/Handlers/MemcachedHandler.php | 4 +--- system/Cache/Handlers/PredisHandler.php | 4 +--- system/Cache/Handlers/RedisHandler.php | 4 +--- system/Cache/Handlers/WincacheHandler.php | 4 +--- system/Test/Mock/MockCache.php | 4 +--- 9 files changed, 16 insertions(+), 37 deletions(-) diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index 0f94cd56f930..0902dcf6f80d 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -51,6 +51,15 @@ public function save(string $key, $value, int $ttl = 60); */ public function delete(string $key); + /** + * Deletes items from the cache store matching a given pattern. + * + * @param string $pattern Cache items glob-style pattern + * + * @return int Number of deleted items + */ + public function deleteMatching(string $pattern): int; + /** * Performs atomic incrementation of a raw stored value. * diff --git a/system/Cache/Handlers/BaseHandler.php b/system/Cache/Handlers/BaseHandler.php index db482952022a..fa93ffe378f0 100644 --- a/system/Cache/Handlers/BaseHandler.php +++ b/system/Cache/Handlers/BaseHandler.php @@ -15,10 +15,8 @@ use Closure; use CodeIgniter\Cache\CacheInterface; -use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Cache; -use Exception; /** * Base class for cache handling @@ -98,18 +96,4 @@ public function remember(string $key, int $ttl, Closure $callback) return $value; } - - /** - * Deletes items from the cache store matching a given pattern. - * - * @param string $pattern Cache items glob-style pattern - * - * @return int - * - * @throws Exception - */ - public function deleteMatching(string $pattern) - { - throw new BadMethodCallException('The deleteMatching method is not implemented.'); - } } diff --git a/system/Cache/Handlers/DummyHandler.php b/system/Cache/Handlers/DummyHandler.php index 10300c79694b..4328f62cfe05 100644 --- a/system/Cache/Handlers/DummyHandler.php +++ b/system/Cache/Handlers/DummyHandler.php @@ -63,10 +63,8 @@ public function delete(string $key) /** * {@inheritDoc} - * - * @return int */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): int { return 0; } diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index 010fc86d9cdd..5b3938e1db0b 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -131,10 +131,8 @@ public function delete(string $key) /** * {@inheritDoc} - * - * @return int */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): int { $deleted = 0; diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index 91ac38a9427d..b19395dcb244 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -182,10 +182,8 @@ public function delete(string $key) /** * {@inheritDoc} - * - * @return never */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): never { throw new BadMethodCallException('The deleteMatching method is not implemented for Memcached. You must select File, Redis or Predis handlers to use it.'); } diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index f7fd936abf59..46e697f50f0c 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -155,10 +155,8 @@ public function delete(string $key) /** * {@inheritDoc} - * - * @return int */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): int { $matchedKeys = []; diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index a79c757fe331..c3455693b8e2 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -179,10 +179,8 @@ public function delete(string $key) /** * {@inheritDoc} - * - * @return int */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): int { /** @var list $matchedKeys */ $matchedKeys = []; diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index d4d97701b135..2207296457d7 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -75,10 +75,8 @@ public function delete(string $key) /** * {@inheritDoc} - * - * @return never */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): never { throw new BadMethodCallException('The deleteMatching method is not implemented for Wincache. You must select File, Redis or Predis handlers to use it.'); } diff --git a/system/Test/Mock/MockCache.php b/system/Test/Mock/MockCache.php index 6699ad266c63..07b44895cd09 100644 --- a/system/Test/Mock/MockCache.php +++ b/system/Test/Mock/MockCache.php @@ -129,10 +129,8 @@ public function delete(string $key) /** * Deletes items from the cache store matching a given pattern. - * - * @return int */ - public function deleteMatching(string $pattern) + public function deleteMatching(string $pattern): int { $count = 0; From 3f67e40537c928259464f1c3e08a03a71e7893e8 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Sun, 23 Nov 2025 19:26:34 +0100 Subject: [PATCH 2/2] docs(changelogs): add note about Cache interface change --- user_guide_src/source/changelogs/v4.7.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 466c67164a44..f9dcb6c82d3f 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -43,6 +43,7 @@ across all insert/update operations. Interface Changes ================= +- **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. - **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. Method Signature Changes