|
Posted by Rasmus Lerdorf on 11/14/33 11:22
Aiguo Fei wrote:
> Thanks your insightful comments. Clearly scalability is a concern for large
> scale applications. One has to be discreet with it if such a facility is
> available. For the dictionary example, I feel it definitely can use such a
> facility and DB approach is much slower; and scalability/load balancing is
> not an issue since no synchronization of any kind is necessary.
>
> I checked APC, but unfortunately it doesn't have any documentation; there is
> a short section on it in "Essential PHP Tools", but appears to be too out of
> date. I checked out the chapter on PHP extentions in "Power PHP5
> programming" book, seems "persistent resource that can survive in between
> requests" seems to do what I have in mind, but again there is no more than
> just mentioning it.
Not much documentation is needed:
if(!$dict = apc_fetch('dict')) {
$dict = function_that_returns_a_dictionary_array_or_object();
apc_store('dict',$dict);
}
That's all. Now you are working with a $dict array or object from
shared memory. If it isn't in shared memory you create it and put it
there, so typically that will only happen on th every first request.
apc_store() has an optional 3rd argument which is the timeout in seconds
for the cache entry.
-Rasmus
Navigation:
[Reply to this message]
|