Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a web search interface that can compare products in a table. This data set changes a few times a week.

I have been storing a "DISTINCT" list (used for parametric selection) in a cache table. The query is computationally expensive because it involves table joins and thousands of records, hence the reason to cache it.

I was wondering if it is a good idea to "cache" certain data in PHP in dynamically generated code.

The idea is that I could create a cache.php file that is 'included' which has the data in arrays for PHP to use without going to the database. This PHP file could be cached using any of the PHP compiler caches out there.

I'm not having speed issues (yet), but I don't like the idea of having to ask the database for cache data, as it seems the overhead of the php->mysql transaction is expensive.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Yes, it's fine. It's a very common practice, and I can't think of a mature framework I've used that doesn't have some sort of code generation caching as part of the optimization scheme.

That said, if your database supports views, I would recommend using that.

share|improve this answer
1  
Generic database views won't help performance. But specifically Materialized Views (Oracle) or Indexed Views may be more helpful. –  codingoutloud Feb 23 '12 at 5:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.