diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3fde2bb..a101b18e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log 2.0.18 under development ------------------------ -- no changes in this release. +- Bug #247: `Cache::getValue()` now returns `false` in case of missing key (rhertogh) 2.0.17 January 11, 2022 diff --git a/UPGRADE.md b/UPGRADE.md index 90aa7e2d7..4f02ad304 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -12,6 +12,16 @@ if you want to upgrade from version A to version C and there is version B between A and C, you need to follow the instructions for both A and B. +Upgrade from 2.0.17 +------------------ + +* The `Cache::getValue()` method now adheres to the specifications and returns `false` in case of a missing + (or expired) key. This might have impact in the following scenarios: + * You specified a custom `Cache::$serializer`, depending on the serializer used `Cache::get()` might now + return `false` instead of `null` in case of a missing (or expired) key. + * You extended the `Cache` class, are using the protected method `Cache::getValue()` directly and expect + a return value of `null` in case of a missing (or expired) key. + Upgrade from 2.0.13 ------------------ diff --git a/src/Cache.php b/src/Cache.php index b64eb8a0d..902d124b3 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -195,7 +195,12 @@ public function exists($key) */ protected function getValue($key) { - return $this->getReplica()->executeCommand('GET', [$key]); + $value = $this->getReplica()->executeCommand('GET', [$key]); + if ($value === null) { + return false; // Key is not in the cache or expired + } + + return $value; } /**