Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] insist on not considering false as cache miss #17476

Merged
merged 1 commit into from
Jan 22, 2017
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
8 changes: 4 additions & 4 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public function get($key)
{
$value = $this->connection()->get($this->prefix.$key);

if (! is_null($value) && $value !== false) {
return $this->unserialize($value);
}
return $this->unserialize($value);
}

/**
Expand Down Expand Up @@ -274,6 +272,8 @@ protected function serialize($value)
*/
protected function unserialize($value)
{
return is_numeric($value) ? $value : unserialize($value);
if (! is_null($value) && $value !== false) {
return is_numeric($value) ? $value : unserialize($value);
}
}
}
16 changes: 6 additions & 10 deletions src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public function __construct(Store $store)
*/
public function has($key)
{
$value = $this->get($key);

return ! is_null($value) && $value !== false;
return ! is_null($this->get($key));
}

/**
Expand All @@ -85,7 +83,7 @@ public function get($key, $default = null)
// If we could not find the cache value, we will fire the missed event and get
// the default value for this cache value. This default could be a callback
// so we will execute the value function which will resolve it if needed.
if (is_null($value) || $value === false) {
if (is_null($value)) {
$this->event(new CacheMissed($key));

$value = value($default);
Expand Down Expand Up @@ -128,7 +126,7 @@ protected function handleManyResult($keys, $key, $value)
// If we could not find the cache value, we will fire the missed event and get
// the default value for this cache value. This default could be a callback
// so we will execute the value function which will resolve it if needed.
if (is_null($value) || $value === false) {
if (is_null($value)) {
$this->event(new CacheMissed($key));

return isset($keys[$key]) ? value($keys[$key]) : null;
Expand Down Expand Up @@ -218,12 +216,10 @@ public function add($key, $value, $minutes)
);
}

$exists = $this->get($key);

// If the value did not exist in the cache, we will put the value in the cache
// so it exists for subsequent requests. Then, we will return true so it is
// easy to know if the value gets added. Otherwise, we will return false.
if (is_null($exists) || $exists === false) {
if (is_null($this->get($key))) {
$this->put($key, $value, $minutes);

return true;
Expand Down Expand Up @@ -285,7 +281,7 @@ public function remember($key, $minutes, Closure $callback)
// If the item exists in the cache we will just return this immediately and if
// not we will execute the given Closure and cache the result of that for a
// given number of minutes so it's available for all subsequent requests.
if (! is_null($value) && $value !== false) {
if (! is_null($value)) {
return $value;
}

Expand Down Expand Up @@ -320,7 +316,7 @@ public function rememberForever($key, Closure $callback)
// If the item exists in the cache we will just return this immediately and if
// not we will execute the given Closure and cache the result of that for a
// given number of minutes so it's available for all subsequent requests.
if (! is_null($value) && $value !== false) {
if (! is_null($value)) {
return $value;
}

Expand Down