APC not working as expected?

Posted by Alix Axel on Stack Overflow See other posts from Stack Overflow or by Alix Axel
Published on 2010-05-15T23:42:17Z Indexed on 2010/05/15 23:50 UTC
Read the original article Hit count: 328

Filed under:
|
|
|
|

I've the following function:

function Cache($key, $value = null, $ttl = 60)
{
    if (isset($value) === true)
    {
        apc_store($key, $value, intval($ttl));
    }

    return apc_fetch($key);
}

And I'm testing it using the following code:

Cache('ktime', time(), 3); // Store

sleep(1);
var_dump(Cache('ktime') . '-' . time()); echo '<hr />'; // Should Fetch
sleep(5);
var_dump(Cache('ktime') . '-' . time()); echo '<hr />'; // Should NOT Fetch
sleep(1);
var_dump(Cache('ktime') . '-' . time()); echo '<hr />'; // Should NOT Fetch
sleep(1);
var_dump(Cache('ktime') . '-' . time()); echo '<hr />'; // Should NOT Fetch

And this is the output:

string(21) "1273966771-1273966772"
string(21) "1273966771-1273966777"
string(21) "1273966771-1273966778"
string(21) "1273966771-1273966779"

Shouldn't it look like this:

string(21) "1273966771-1273966772"
string(21) "-1273966777"
string(21) "-1273966778"
string(21) "-1273966779"

I don't understand, can anyone help me figure out this strange behavior?

© Stack Overflow or respective owner

Related posts about php

Related posts about apc