Skip to content
Advertisement

Aggressive caching of generated contents while maintaining auth info

I’m using a Symfony 2 to generate my pages from data in a MySQL database. For most content, users have to be authenticated but the content itself does not change often and does not need to be customized for the users. So what’s a good caching strategy for avoiding database calls while still maintaining the auth check?

Advertisement

Answer

I solved this by using Zend_Cache inside the cacheable actions to store the rendered template result. I then create a new Response object from the cached content. If the cache is empty, I generate the content.

I thought of creating a plugin that checks for an annotation and stores the Response output automatically but it turned out that I only have 3-4 display actions that are cacheable and have very complex cache ID creation rules, so I put the caching logic directly into the controller code.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement