Changeset 1304
- Timestamp:
- 05/03/06 09:41:50 (3 years ago)
- Files:
-
- trunk/doc/book/content/cache.txt (modified) (7 diffs)
- trunk/doc/book/content/templating_configuration.txt (modified) (1 diff)
- trunk/doc/book/content/view.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/doc/book/content/cache.txt
r1273 r1304 14 14 As all the pages may contain dynamic information, the HTML cache is disabled by default. It is up to the site administrator to activate it in order to improve performance. 15 15 16 Symfony handles three different types of HTML cache: 17 18 * cache of the result of an action 16 Symfony handles four different types of HTML cache: 17 18 * cache of an action 19 * cache of a partial, a component, or of a component slot 19 20 * cache of an entire page 20 21 * cache of a fragment of a template 21 22 22 The t wofirst types are handled with YAML configuration files, the last one is managed by calls to helper functions in the template.23 The three first types are handled with YAML configuration files, the last one is managed by calls to helper functions in the template. 23 24 24 25 The symfony cache system uses files stored on the web server hard disk. This keeps the cache simple and efficient, without any other prerequisites than the framework itself. It is not yet possible to cache in memory or in a database. … … 43 44 One other cache parameter can be changed in the `settings.yml` file: The default cache lifetime, i.e. the number of seconds after which a cached file is overwritten and the page processed again. The default `default_cache_lifetime` is set to one day, or 86400 seconds. 44 45 45 Caching the result ofan action46 ----------------- --------------47 48 Actions that display static information (i.e. without any call to a database) or actions that read the information in a database but without modifying it are often good clients for caching.46 Caching an action 47 ----------------- 48 49 Actions that display static information (i.e. without any call to a database) or actions that read the information in a database but without modifying it (typically GET requests) are often good clients for caching. 49 50 50 51 For instance, imagine an action that returns the list of all the users of your website (`user/list`). Unless a user is modified, added or removed (and this matter will be discussed later), this list always displays the same information, so it is a good candidate for caching. … … 61 62 lifeTime: 86400 62 63 63 This configuration stipulates that the cache is `on` for the `list` action, and that it is of the `slot` type (i.e. caching the result ofan action, as opposed to caching the whole page, which will be described later). The `lifeTime` is the time (in seconds) after which the page will be processed again and the cached version replaced.64 This configuration stipulates that the cache is `on` for the `list` action, and that it is of the `slot` type (i.e. caching an action, as opposed to caching the whole page, which will be described later). The `lifeTime` is the time (in seconds) after which the page will be processed again and the cached version replaced. 64 65 65 66 Now, if you try to call this action from your browser (probably by requesting an URL like `http://myapp.example.com/user/list`), you will notice no difference the first time, but refreshing the page will probably show a notable boost in response time. … … 72 73 73 74 Now, requests like `http://myapp.example.com/user/show/id/12` will create new records in the cache folder and if you repeat this request, it will be much faster the second time. 75 76 Caching a partial, a component, or a component slot 77 --------------------------------------------------- 78 79 The [view chapter](view.txt) explains how to reuse code fragments across several templates, using the `include_partial()` helper. 80 81 [php] 82 <?php include_partial('mymodule/mypartial') ?> 83 84 A partial is as easy to cache as an action. To activate it, create a `cache.yml` in the partial module `config/` directory (in the example above, in `modules/mymodule/config/`) and activate the cache for the partials by declaring their names with a trailing underscore: 85 86 _mypartial: 87 activate: on 88 89 all: 90 activate: off 91 92 Now all the templates using this partial won't actually execute the PHP code of the partial, but use the cached version instead. 93 94 >**Note**: The `slot` type cache is more powerful than the partial cache, since when an action is cached, the template is not even executed - and if the template contains calls to partials, theses calls are not performed. Therefore, the partial caching is useful only if you don't use action caching in the caling action. 95 96 Just like for actions, partial caching is also relevant when the result of the partial depends on parameters: 97 98 [php] 99 <?php include_partial('mymodule/my_other_partial', array('foo' => 'bar)) ?> 100 101 A component is a lightweight action put on top of a partial. A component slot is a component for which the action varies according to the calling actions. These two inclusion types are very similar to partials, and support caching the same way. For instance, if your global layout shows a: 102 103 [php] 104 <?php include_component('global/day') ?> 105 106 ...in order to show the current date, then you can cache this component with such a `cache.yml`: 107 108 _day: 109 activate: on 110 111 >**Note**: Global components (the ones located in the application `templates/` directory) can be cached, provided you declare the activation in the application `cache.yml` file. 74 112 75 113 Caching an entire page … … 98 136 ...the full pages will be completely cached, and the second time you request them, the response will be even faster than with the action result cached. 99 137 100 Unfortunately, the layout often contains some dynamic elements, including [ slots](view.txt). So the cases where the whole page can be cached are not very common. As a matter of fact, this type is often most used for RSS feeds, pop-ups, or pages with a layout that doesn't depend on cookies.138 Unfortunately, the layout often contains some dynamic elements, including [component slots](view.txt). So the cases where the whole page can be cached are not very common. As a matter of fact, this type is often most used for RSS feeds, pop-ups, or pages with a layout that doesn't depend on cookies. 101 139 102 140 Caching a template fragment … … 174 212 The files stored in these folders depend on the type of caching used: 175 213 176 cache type | file name177 ---------- | ---------178 slot | slot.cache179 page | page.cache180 fragment | fragment_users.cache181 | fragment_other_unique_name.cache182 | ...214 cache type | file name 215 -------------------------- | --------- 216 slot, partial, components | slot.cache 217 page | page.cache 218 fragment | fragment_users.cache 219 | fragment_other_unique_name.cache 220 | ... 183 221 184 222 The name given to a fragment in the `cache()` helper is concatenated after `fragment_`. Here, the second fragment was generated by: … … 188 226 ... 189 227 190 If you use slots in the layout, remember that their cache files are found in a tree structure relative to the module/action of the slot, not the module/action initially called.228 If you use component or component slots in the layout, remember that their cache files are found in a tree structure relative to the module/action of the slot, not the module/action initially called. 191 229 192 230 Feel free to browse the cache folder to look at the chunks of code that are saved; you might feel more comfortable with the cache if you see that it only saves what it is supposed to save. trunk/doc/book/content/templating_configuration.txt
r1118 r1304 371 371 ... 372 372 <div id="adviceBlock"> 373 <?php echoinclude_component_slot('advices') ?>373 <?php include_component_slot('advices') ?> 374 374 </div> 375 375 ... trunk/doc/book/content/view.txt
r1118 r1304 351 351 352 352 [php] 353 <?php echoinclude_component('news', 'headlines') ?>353 <?php include_component('news', 'headlines') ?> 354 354 355 355 Just like the partials, components accept additional parameters in the shape of an associative array. … … 368 368 ... 369 369 <div id="#sidebar"> 370 <?php echoinclude_component_slot('sidebar') ?>370 <?php include_component_slot('sidebar') ?> 371 371 </div> 372 372