12.07.2015 Views

A Gentle Introduction to symfony (pdf) - Bad Request

A Gentle Introduction to symfony (pdf) - Bad Request

A Gentle Introduction to symfony (pdf) - Bad Request

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12: Caching 205_day:contextual: trueenabled: trueListing12-11Global components (the ones located in the application templates/ direc<strong>to</strong>ry) can becached, provided that you declare their cache settings in the application cache.yml.Caching a Template FragmentAction caching applies <strong>to</strong> only a subset of actions. For the other actions—those that updatedata or display session-dependent information in the template—there is still room for cacheimprovement but in a different way. Symfony provides a third cache type, which is dedicated<strong>to</strong> template fragments and enabled directly inside the template. In this mode, the action isalways executed, and the template is split in<strong>to</strong> executed fragments and fragments in thecache, as illustrated in Figure 12-3.Figure 12-3 - Caching a template fragmentFor instance, you may have a list of users that shows a link of the last-accessed user, and thisinformation is dynamic. The cache() helper defines the parts of a template that are <strong>to</strong> be putin the cache. See Listing 12-5 for details on the syntax.Listing 12-5 - Using the cache() Helper, in frontend/modules/user/templates/listSuccess.phpListing12-12Here’s how it works:• If a cached version of the fragment named ‘users’ is found, it is used <strong>to</strong> replace thecode between the and the lines.• If not, the code between these lines is processed and saved in the cache, identifiedwith the unique fragment name.----------------- Brought <strong>to</strong> you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!