How do I choose what and when to cache data with ob_start rather than query the database?

Posted by Tim Santeford on Stack Overflow See other posts from Stack Overflow or by Tim Santeford
Published on 2010-05-12T17:41:07Z Indexed on 2010/05/12 17:54 UTC
Read the original article Hit count: 155

Filed under:
|
|

I have a home page that has several independent dynamic parts. The parts consist of a list of recent news from the company, a site statistics panel, and the online status of certain employees. The recent news changes monthly, site statistics change daily, and online statuses change on a per minute bases. I would like to cache these panels so that the db is not hit on every page load.

Is using ob_start() then ob_get_contents() to cache these parts to a file the correct way to do this or is there a better method in PHP5 for doing this?

In asking this question I'm trying to answer these additional questions:

  • How can I determine the correct approach for caching this data without doing extensive benchmarking?
  • Does it make sense to cache these parts in different files and then join them together per requests or should I re-query the data and cache once per minute?

I'm looking for a rule of thumb for planning pages and for situations where doing testing is not cost effective (The client is not paying enough for it I mean).

Thanks!

© Stack Overflow or respective owner

Related posts about php5

Related posts about cache