Component caching

Many web applications contain dynamic data in each page, and this is the reason why the use of cache to enhance the response time is often limited. For instance, consider a page resulting of an action decorated by a layout including components:

example page layout

The action and the three components are all dynamic, but only the component B depends on the session.

Symfony already contains the mechanisms to cache the action or the whole page (see more in the cache chapter of the symfony book). This way, even if your action contains queries to the database, it is only executed once. The page cache type is the fastest, but it doesn't allow for data depending on the session in the page. The slot cache type is the more versatile, but it is not as efficient as the page type since the layout - and its components - still have to be executed.

slot and page cache

The great news is, symfony now supports components cache. This means that you can combine performance and versatility to achieve something like:

slot and page cache

That's right: you can declare every session-independent part of a page (action, components A and C in the example) as cached, and only the very dynamic parts (component B in the example) will be executed when the page is requested. Think about displaying data from a content management system in a page where you also want to show if the user is logged or not, and you will understand that this is a very common situation.

Add to that the ability to use components from inside a template (the result of an action), and the ability to use components from inside a partial (or the view of another component), and you have the best tool for performance in a dynamic website.

Components cache is available since the release 1300 and is documented here.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


awesome, a well needed enhancement.
wahoo :-)
an rss feed of this blog would be a nice addition :)
There is a feed for this weblog:
awesome, you might want to put that info somewhere handy to grab ;)
Well, all rss-feeds are listed unter "Community"
bladus, thanks for the info but for them to be useful I should be able to scan the page and immediately see where it is--err on the side of the busy user, that's my policy.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.