Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions system/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace CodeIgniter\Cache;

use Closure;

interface CacheInterface
{
/**
Expand All @@ -38,6 +40,16 @@ public function get(string $key): mixed;
*/
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.
*
Expand Down
7 changes: 0 additions & 7 deletions system/Cache/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ 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()``.

Expand Down
Loading