Search code examples
drupaldrupal-7hamlapc

How to cache PHP code being called from the database?


I've got some pages (or "nodes" in Drupal parlance) that have the content of a PHP function which calls an external library to render a HAML template. These nodes (meaning the actual <?php ?> tags and functions to call the library) are stored in the database and go through some sort of eval style call when the page is requested.

If I'm using APC, will the opcodes for the functions stored in the database still cache? Or will it go through a fresh cycle of requesting the library, running the function, generating the output, and storing that to be echoed every time the page is hit?


Solution

  • APC does not cache optimized evaluated code, at least not yet. To take advantage of it, you should dump it to disk. If there's no sensitive data in the code, you could use a temporary file and only store in APC the filename/key for retrieving it. Then you should only update the file if the information needed to generate the code in the database is updated.