I've found an article on the net talking about, caching query results
in a folder,
it converts the SQL statement in his MD% to have a filename for the cache file by default.
Then it saves all queries in your configured dir.

Anytime you perform a query u pass to your custom Class for DB caching the TTL
for this query. Then it performs filemtime on the cache MD5 file, and if it is old it will
replace it renewing the MySQL query result from DB , otherwise it will output the file contents.
Query results are saved serialized in the file, and then need to unserialize.

Nice Idea!

But........does this really improve performances? I've some doubts on it since the cache writing/reading activity could be not that light task (for PHP process) as one can think.... (am I wrong?)

What are your opinions?

Many thanks

    It depends* - i would only apply caching or any optimization after real world testing. There are many strategics and products for this sort of thing (mysql does its own caching to).

    average site- average host I wouldn't bother, large site- I would look at the many available options.

    *hardware,software,query size, frequency of access,frequency of change ...

      4 days later

      "it depends" is the right answer. To really find out, you would have to test it under real-life circumstances. To get a good idea, you would need to test it under simulated circumstances.

      dagon is right that mysql caches its queries. I believe this caching is done in RAM which would be much faster than file caching AFAIK. Your my.cnf (the MySQL configuration file) has config values related to how much memory you allocate to the query cache. MySQL takes care of checking the query cache or flushing it if your tables have changed. This really helps performance under certain conditions (i.e., the exact same query is run many times on a server).

      As for your query caching, you might want to ask yourself if this cache gets out of date when your data changes and whether the caching takes that into account.

        6 days later

        Actually I made a class with funcltionaLities I described in my prev. post. Well now page request takes about 400 ms versus the 4 seconds or more uncached. And more without any cache I noticed the latency of php-mysql execution increAses exponentially until points of down of service. Maybe this is due also that my websrv is a vps so not thAt efficient like the real thing and also that it mounts 2 web portals with 3000 unique visitors per day sharing the same mysql process. Anyway until now the solution of saving a serialized array of mysql resultset is giving my good results. We will see. And also this is an easier solution respect to xml. No pain with xml dom. 🙂

          Write a Reply...