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(11) "-1273966777"
string(11) "-1273966778"
string(11) "-1273966779"
I don't understand, can anyone help me figure out this strange behavior?