Storing Null In Cache #52449
Unanswered
kellerjmrtn
asked this question in
General
Replies: 1 comment
-
I'd go with Cache:;get('key')?:null. I completely agree with you... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
According to PSR-16 (which
Illuminate\Cache\Repository
implements)If a
null
value is fundamentally indistinguishable from simply not setting the value at all, is there any reason to set anull
value? For example (using Redis store, for example)Despite the key physically being set in Redis, it's seemingly indistinguishable from a key that was never set:
Therefore, does it even make sense to set a
null
value in cache in the first place? Admittedly I don't know implementation specifics, so it's possible not doing so could cause some undesired behavior somewhere that I'm unaware of. But it seems like avoiding settingnull
could potentially have a few (minor) performance benefits:put
,remember
, etcSuggested Change
Since
Illuminate\Cache\Repository
does set a real key/value pair in cache when the value isnull
, I'm suggesting/wondering whether it makes sense to update that implementation to simply not set the key/value pair at allBeta Was this translation helpful? Give feedback.
All reactions