What's the usage of apc_store();
and apc_fetch();
on the following example?
function getData($uid){
$cached = apc_fetch($uid);
return $cached?$cached:"Start";
}
function setData($uid,$step){
apc_store($uid,$step,60*60*12);
}
I want to store string and then use it later. I can't understand the main and general explanations about these two functions in PHP.
The first method
getData($uid)
simply returns the value of $uid from cache and if there is not variable for the key $uid then it will returns a string "Start". So simply returns the value of $uid from cache.And the second method
setData($uid,$step)
defines a variable in cache as $uid storing the value as $step with ttl 60*60*12.TTL is the time that defines life of the cached variable $uid. (Time To Live; store var in the cache for ttl seconds.)
For more detail, see:
Also take a look at apc