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

Conversation

@stevelacey
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2019

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 force-pushed the stevelacey:patch-1 branch from 29cd04f to e9cf79d 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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@stevelacey stevelacey deleted the stevelacey:patch-1 branch Aug 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.