From c9c3dac98685cc9858f21dee92b91866ee0fc01f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 8 Jan 2026 10:47:14 +0330 Subject: [PATCH 1/6] feat: add emember() to CacheInterface --- system/Cache/CacheInterface.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index 9ae83f29283d..6241a0365934 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -13,6 +13,8 @@ namespace CodeIgniter\Cache; +use Closure; + interface CacheInterface { /** @@ -37,6 +39,16 @@ public function get(string $key): mixed; * @return bool Success or failure */ public function save(string $key, mixed $value, int $ttl = 60): bool; + + /** + * Attempts to get an item from the cache, or executes the callback + * and stores the result on cache miss. + * + * @param string $key Cache item name + * @param int $ttl Time To Live, in seconds + * @param Closure(): mixed $callback Callback executed on cache miss + */ + public function remember(string $key, int $ttl, Closure $callback): mixed; /** * Deletes a specific item from the cache store. From 4f3d44b3ef7ebdc0a759638251454a2dfc9604b5 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 8 Jan 2026 10:53:35 +0330 Subject: [PATCH 2/6] docs: note addition of emember() to CacheInterface --- user_guide_src/source/changelogs/v4.7.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index e8124847efc2..30bc417c418d 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -182,6 +182,8 @@ Interface Changes - **Cache:** The ``CacheInterface`` now includes the ``deleteMatching()`` method. - **Database:** The ``QueryInterface`` now includes the ``getOriginalQuery()`` method. - **Images:** The ``ImageHandlerInterface`` now includes a new method: ``clearMetadata()``. +- **Cache:** The ``CacheInterface`` now includes the ``remember()`` method. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them. +If you have implemented your own caching driver directly from ``CacheInterface``, you will need to provide an implementation for ``remember()`` to maintain compatibility. Method Signature Changes ======================== From e79198f57e022ce7e93e30583ac9723876bdbbf2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 8 Jan 2026 11:00:41 +0330 Subject: [PATCH 3/6] style: fix code style --- system/Cache/CacheInterface.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index 6241a0365934..4cedb67e9538 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -39,13 +39,13 @@ public function get(string $key): mixed; * @return bool Success or failure */ public function save(string $key, mixed $value, int $ttl = 60): bool; - + /** * Attempts to get an item from the cache, or executes the callback * and stores the result on cache miss. * - * @param string $key Cache item name - * @param int $ttl Time To Live, in seconds + * @param string $key Cache item name + * @param int $ttl Time To Live, in seconds * @param Closure(): mixed $callback Callback executed on cache miss */ public function remember(string $key, int $ttl, Closure $callback): mixed; From 8e0fc7d34620ff474eb83e1ad37e035d917817f9 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 8 Jan 2026 11:05:23 +0330 Subject: [PATCH 4/6] docs: fix UG style --- user_guide_src/source/changelogs/v4.7.0.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 30bc417c418d..91070d15cdc2 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -182,8 +182,7 @@ Interface Changes - **Cache:** The ``CacheInterface`` now includes the ``deleteMatching()`` method. - **Database:** The ``QueryInterface`` now includes the ``getOriginalQuery()`` method. - **Images:** The ``ImageHandlerInterface`` now includes a new method: ``clearMetadata()``. -- **Cache:** The ``CacheInterface`` now includes the ``remember()`` method. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them. -If you have implemented your own caching driver directly from ``CacheInterface``, you will need to provide an implementation for ``remember()`` to maintain compatibility. +- **Cache:** The ``CacheInterface`` now includes the ``remember()`` method. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them. If you have implemented your own caching driver directly from ``CacheInterface``, you will need to provide an implementation for ``remember()`` to maintain compatibility. Method Signature Changes ======================== From 82a4d5a679dbe72ec89640dd3163f6b70055bd9d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Mon, 19 Jan 2026 15:43:47 +0800 Subject: [PATCH 5/6] Update changelog --- user_guide_src/source/changelogs/v4.7.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 91070d15cdc2..2fb147b2d1b8 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -180,9 +180,9 @@ Interface Changes **NOTE:** If you've implemented your own classes that implement these interfaces from scratch, you will need to update your implementations to include the new methods to ensure compatibility. - **Cache:** The ``CacheInterface`` now includes the ``deleteMatching()`` method. +- **Cache:** The ``CacheInterface`` now includes the ``remember()`` method. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them. - **Database:** The ``QueryInterface`` now includes the ``getOriginalQuery()`` method. - **Images:** The ``ImageHandlerInterface`` now includes a new method: ``clearMetadata()``. -- **Cache:** The ``CacheInterface`` now includes the ``remember()`` method. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them. If you have implemented your own caching driver directly from ``CacheInterface``, you will need to provide an implementation for ``remember()`` to maintain compatibility. Method Signature Changes ======================== From 6349e0c59276a15dc16fe0bbd471b9d71a1d1e73 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Mon, 19 Jan 2026 15:45:04 +0800 Subject: [PATCH 6/6] Update BaseHandler --- system/Cache/Handlers/BaseHandler.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/system/Cache/Handlers/BaseHandler.php b/system/Cache/Handlers/BaseHandler.php index 2d9aeff489d1..4f7022d3c249 100644 --- a/system/Cache/Handlers/BaseHandler.php +++ b/system/Cache/Handlers/BaseHandler.php @@ -75,13 +75,6 @@ public static function validateKey($key, $prefix = ''): string return strlen($prefix . $key) > static::MAX_KEY_LENGTH ? $prefix . md5($key) : $prefix . $key; } - /** - * Get an item from the cache, or execute the given Closure and store the result. - * - * @param string $key Cache item name - * @param int $ttl Time to live - * @param Closure(): mixed $callback Callback return value - */ public function remember(string $key, int $ttl, Closure $callback): mixed { $value = $this->get($key);