Why design such an API for Context that is inconsistent with Cache? #52364
Unanswered
SyuTingSong
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've recently been reviewing the new features of Laravel 11 and noticed the newly introduced
Context
. It's great, however, the method names are quite perplexing.After reading through the Context documentation, I've come to understand that Context is a key-value store shared between Log and other programs.
But it uses the
add
method to set a value, and the documentation specifically points out that it will overwrite an existing key. If you just want to add a value only when the key does not exist in Context, you have to useaddIf
. What's addIf? It seems like a condition and a pair of key-value should be passed as the parameters, but in fact, it receives just the key and value. The documentation even has to point out that to achieve the real conditional put values, you need to use thewhen
method.I can't understand why the author didn't use
put
andadd
as the Context method names, considering everyone is already accustomed to them from usingCache
in Laravel.Beta Was this translation helpful? Give feedback.
All reactions