n a
n a

Reputation: 2802

Can cache data be destroyed between apc_exist() and apc_fetch() calls within the same script?

In the following example

if (apc_exists('foo'))
{
    echo apc_fetch('foo');
}

Is it possible that apc_exists('foo') returns TRUE but apc_fetch('foo') returns FALSE because the data was deleted (manually or due to cache reset) between those two calls?

Upvotes: 1

Views: 178

Answers (1)

Markus Malkusch
Markus Malkusch

Reputation: 7868

From what I read in the documentation it's designed to be consistent per request:

After the ttl has passed, the stored variable will be expunged from the cache (on the next request)

OTH If you have something like apc_delete() on another thread a Non-Repeatable Read is possible. I would recommend to refactor your code to one atomic apc_fetch() only:

$foo = apc_fetch("foo", $exist);
if ($exist) {
    echo $foo;

}

Upvotes: 1

Related Questions