Page 1 of 1

Persistent objects?

Posted: Thu Oct 04, 2007 6:16 pm
by impromptu77
I'm trying to maintain a lot of common objects that will be used by many pages, but am trying to avoid the hit of reloading the information from a file or database for every page request.

For example, if I want to build an NLS such that I can make a call to get a phrase/word in a particular language, it will require maintaining a translation file with 1,000 terms and every time a page is requested, I want to just have that in memory for quick access rather than rereading it from disk/database.

Another example is I have global properties for my web site that are stored in the database, but they are used so frequently that I'd like to avoid the current overhead of querying the database on every page request.

Any suggestions on how to do this?

(Moderators, I'm not sure if this posting should be under Theory and Design - please feel free to move this to the appropriate location)

Posted: Thu Oct 04, 2007 6:21 pm
by Christopher
Save it in the session or put it into a faster form -- like a file. For the file you could put it in code or config or YAML or XML or serialize it or ...

But with PHP everything has to load every request. The choice is what sub-system to use. If you need more speed then put the above files on a RAM disk.

Posted: Fri Oct 05, 2007 1:37 pm
by Weirdan
or in memcached

Posted: Fri Oct 05, 2007 1:57 pm
by s.dot
Does this site receive a lot of traffic? If not, selecting 1 field (the serialized object) from a database using a query won't be that much hassle at all.

Posted: Fri Oct 05, 2007 7:06 pm
by impromptu77
Yes, the site receives a fair amount of traffic and I don't want to use unnecessary database connections if I can avoid it. I hadn't heard of memcached before, will look into that. Thanks for all the suggestions so far!

Posted: Sat Oct 06, 2007 4:02 am
by Kieran Huggins
If you're connecting to the database anyway, I would consider using a HEAP table. It resides entirely in memory and the query overhead would be minimal. Maybe even faster than reading a static file!