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.8] Array cache forget should return false on missing key #29427

Merged
merged 1 commit into from
Aug 6, 2019
Merged

[5.8] Array cache forget should return false on missing key #29427

merged 1 commit into from
Aug 6, 2019

Conversation

stevelacey
Copy link
Contributor

@stevelacey stevelacey commented Aug 6, 2019

The array cache driver currently returns true for all forget() calls. I think it should return false if there was no matching key, to better match the other drivers like memcached and redis.

I based this PR to 5.8 given anyone checking the return value of forget is probably expecting this behaviour? Not sure if this is BC incompatible enough to warrant pushing it to 6.0.

I am using the return value of forget to show whether a nonce is valid, so was expecting a true (and for the nonce to then be removed), and subsequent false's which works fine via the redis and memcached drivers, but not in the tests which use array.

@stevelacey
Copy link
Contributor Author

Note, I used array_key_exists to ensure a true is returned when a cache key is set to null, which seems to be consistent with the other drivers

memcached, redis (and array, after this change):

>>> Cache::put('test', null)
=> true
>>> Cache::has('test')
=> false
>>> Cache::forget('test')
=> true
>>> Cache::forget('test')
=> false

array before this change:

>>> Cache::put('test', null)
=> true
>>> Cache::has('test')
=> false
>>> Cache::forget('test')
=> true
>>> Cache::forget('test')
=> true

@stevelacey stevelacey changed the title Array cache should return false on missing key Array cache forget should return false on missing key Aug 6, 2019
@stevelacey stevelacey changed the title Array cache forget should return false on missing key [5.8] Array cache forget should return false on missing key Aug 6, 2019
@taylorotwell taylorotwell merged commit 29b5be4 into laravel:5.8 Aug 6, 2019
@stevelacey stevelacey deleted the patch-1 branch August 7, 2019 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants