1

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.

    1 Answer 1

    0

    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.

    1
    • 1
      Generic database views won't help performance. But specifically Materialized Views (Oracle) or Indexed Views may be more helpful.CommentedFeb 23, 2012 at 5:37

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.