lighttpd forum XCache > xcache_isset and xcache_get and garbage collection

Posted by Bernard Hurley
on 15.06.2008 11:38
Hi all,

I have been writing code like:

if (xcache_isset("abc")) {
    $value = xcache_get("abc");
    ........

However it strikes me that the string could be garbage collected in 
between the 'isset' and the 'get'. What happens in this case? Does 
xcache_get return an empty string? If so it might be safer to write code 
like:

if($value = xcache_get("abc")) {
    .........

I guess I am making the assumption that I never cache an empty string, 
but it is easy to code round that.

What does anyone else think?

Thanks,

Bernard.
Posted by moo XCache
on 15.06.2008 15:12
> if (xcache_isset("abc")) {
>     $value = xcache_get("abc");
>     ........
> 
> However it strikes me that the string could be garbage collected in 
> between the 'isset' and the 'get'. What happens in this case? Does 
you're right, there's a race condition here
> xcache_get return an empty string? If so it might be safer to write code 
> like:
> 
> if($value = xcache_get("abc")) {
>     .........
> 
> I guess I am making the assumption that I never cache an empty string, 
> but it is easy to code round that.
xcache_get issue no warning when data is not found, just return NULL.
u can do this way if you avoid storing NULL when xcache_set().
Posted by Bernard Hurley
on 15.06.2008 15:22
Thanks!

moo XCache wrote:
> xcache_get issue no warning when data is not found, just return NULL.
> u can do this way if you avoid storing NULL when xcache_set().