It's a default value in case of a miss - it's there mainly to support an
edge-case where someone is caching NULL values, and might need to pass a
different default value, so they can tell the difference between a cached
NULL-value and an actual miss.

So in your case:

    $default = new stdClass(); // unique object representing a cache-miss

    $myValue = $myCache->get('foo', $default); // might return a cached NULL

    if ($myValue === $default) { // definitely a cache-miss
        $myValue = someExpensiveOperation(); // might return NULL

        $myCache->set('foo', $myValue); // might cache a NULL
    }

At least that's my understanding.


On Wed, Mar 15, 2017 at 3:22 PM, Brad Kent <kent.b...@gmail.com> wrote:

> 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 a topic in the
> Google Groups "PHP Framework Interoperability Group" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/php-fig/kSj_yVbkwOw/unsubscribe.
> To unsubscribe from this group and all its topics, 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/c5c2a162-2b04-4a70-a5d4-966099831940%40googlegroups.com
> <https://groups.google.com/d/msgid/php-fig/c5c2a162-2b04-4a70-a5d4-966099831940%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CADqTB_iKdOe8RGtFNiEgmn3DYtopLkGAgSY%3DLfj9YCJVxfku7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to