From 341e921b54d65dbde9aa2e55e887dd472cd70dbb Mon Sep 17 00:00:00 2001 From: salehhashemi1992 <81674631+salehhashemi1992@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:41:14 +0330 Subject: [PATCH] change remember signature --- README.md | 2 +- src/ConfigurableCache.php | 4 ++-- tests/ConfigurableCacheTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 14157c6..397b186 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ $value = ConfigurableCache::get('testKey', 'short'); ConfigurableCache::delete('testKey', 'otp'); // if `testKey` doesn't exist in the 'default' cache, the Closure will be executed and its result will be stored in the cache under `testKey` with `_default_` prefix -$value = ConfigurableCache::remember('testKey', 'default', function () { +$value = ConfigurableCache::remember('testKey', function () { return 'Hello World!'; }); ``` diff --git a/src/ConfigurableCache.php b/src/ConfigurableCache.php index b74f04f..99b34dc 100644 --- a/src/ConfigurableCache.php +++ b/src/ConfigurableCache.php @@ -17,11 +17,11 @@ class ConfigurableCache * @template TCacheValue * * @param string $key The cache key to retrieve or store the item. - * @param string $config The cache configuration to use (e.g., 'default'). * @param \Closure(): TCacheValue $callback The Closure to execute if the item is not found in the cache. + * @param string $config The cache configuration to use (e.g., 'default'). * @return TCacheValue The cached item or the result of the Closure execution. */ - public static function remember(string $key, string $config, Closure $callback): mixed + public static function remember(string $key, Closure $callback, string $config = 'default'): mixed { $cacheKey = static::cacheKey($key, $config); $ttl = static::ttl($config); diff --git a/tests/ConfigurableCacheTest.php b/tests/ConfigurableCacheTest.php index 0307e2d..c64a42a 100644 --- a/tests/ConfigurableCacheTest.php +++ b/tests/ConfigurableCacheTest.php @@ -48,7 +48,7 @@ public function test_increment_function_increments_cache_value() public function test_remember_function_stores_closure_result_in_cache() { - ConfigurableCache::remember('testKey', 'default', function () { + ConfigurableCache::remember('testKey', function () { return 'testValue'; });