[Tutor] Re: Tutor digest, Vol 1 #2371 - 11 msgs
Wed Apr 16 04:10:02 2003
On Wed, Apr 16, 2003 at 09:32:45AM +0700, Nova Sano S. Surbakti wrote:
> What I think I want to do is:
> Load data from table then keep it in memory. Each time the SearchForm
> want to get the data, it don't have to touch MySQL again, but search
> the data from memory?
> What I'm doing right now is get the data from MySQL each time the
> SearchForm executed, and it seems too slow.
If I catch you right, your program is executed once for every search made, is
that so? In that case there really isn't any way for you to share the data
manually between the different executions. However, I do not think it should be
a problem. What will happen is that after you first catch the data from mysql,
your computer will buffer that data in memory, as long as it has the space to do
so. So subsequent searches will have to touch MySQL again, but the request will
not take close to as long as the first one because the data is cached (assuming
there isn't a long time between your searches so your computer has decided to
replace the data in the cache with more recent things). I would say that it is
totally feasible to do the request from the database every time, after all,
that's what databases are for :).
If you really really want to share the data in an object between searches, it
gets a bit complicated. You need to have a process running all the time then,
because you can't have control over the memory otherwise. Then when the search
is made your newly started process could communicate with the always running one
and get the data that way. But I don't even think this will be faster than
reading from MySQL all the time, because that data will be in memory too. And if
it isn't, your OS has chosen to discard it to get something more important in,
it probably had a good reason to do so (that is your program haven't been ran
in a while and the memory could be used for better things).