You can use `$default` in conjunction with the Null Object pattern 
<https://en.wikipedia.org/wiki/Null_Object_pattern>. Whereby you usually 
don't want to cache *Null Objects*.

For example for message board users:

class UnknownUser implements User {…} // Null Object Class, providing 
proper avatar etc.

$unknownUser = new UnknownUser(); // N.B. $unknownUser is created only 
once, but can be reused multiple times 

// somewhere:
$user = $userCache->get('name of deleted user', $unknownUser);
$view->render('comment.html', ['user' => $user, …]);

This may make your code less complex 
<https://en.wikipedia.org/wiki/Cyclomatic_complexity>, thus easier to read 
and understand – you do not need `if ($user === null) {…}` after each 
`->get()`.


Am Mittwoch, 15. März 2017 15:22:09 UTC+1 schrieb Brad Kent:
>
> I know I'm late to the party, but what's the use-case for passing a 
> default value to the get method?
>
> If we're using a cache isn't generating/getting the value expensive?
> It seems to encourage something boneheaded like: 
>
> $default = someExpensiveOperation();
> $myValue = $myCache->get('foo', $default);
>
> I could understand passing a callable that would set the value for a cache 
> miss...
>

-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to php-fig+unsubscr...@googlegroups.com.
To post to this group, send email to php-fig@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/203c8680-35eb-487c-8af1-b1baf6115880%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to