Development

Changeset 8317

You must first sign up to be able to contribute.

Changeset 8317

Show
Ignore:
Timestamp:
04/05/08 16:48:24 (3 months ago)
Author:
francois
Message:

[doc 1.1] documented cache improvements

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doc/branches/1.1/book/12-Caching.txt

    r8283 r8317  
    252252>           cacheDir:                %SF_TEMPLATE_CACHE_DIR% 
    253253> 
    254 >You can replace the `class` with your own cache storage class or with one of the symfony alternative classes (including `sfAPCCache`, `sfEAcceleratorCache`, `sfMemcacheCache`, `sfSQLiteCache`, and `sfXCacheCache`). The parameters defined under the `param` key are passed to the constructor of the cache class as an associative array. Any view cache storage class must implement all methods found in the abstract `sfCache` class. Refer to the API documentation ([http://www. symfony-project.com/api/symfony.html](http://www. symfony-project.com/api/symfony.html)) for more information on this subject. 
     254>You can replace the `class` with your own cache storage class or with one of the symfony alternative classes (including `sfAPCCache`, `sfEAcceleratorCache`, `sfMemcacheCache`, `sfSQLiteCache`, and `sfXCacheCache`). The parameters defined under the `param` key are passed to the constructor of the cache class as an associative array. Any view cache storage class must implement all methods found in the abstract `sfCache` class. Refer to the Chapter 19 for more information on this subject. 
    255255 
    256256### Using the Super Fast Cache 
  • doc/branches/1.1/book/13-I18n-and-L10n.txt

    r8283 r8317  
    343343If additional translations need to be done, simply add a new `messages.``XX``.xml` translation file in the same directory. 
    344344 
     345>**TIP** 
     346>As looking for dictionary files, parsing them, and finding the correct translation for a given string takes some time, symfony uses an internal cache to speedup the process. By default, this cache uses the filesystem. You can configure how the i18N cache works (for instance, to share the cache between several servers) in the `factories.yml` (see Chapter 19). 
     347 
    345348### Managing Dictionaries 
    346349 
  • doc/branches/1.1/book/19-Mastering-Symfony-s-Configuration-Files.txt

    r8283 r8317  
    106106  * The pattern routing uses its own cache, in production mode, to speed up conversions between external URLs and internal URIs. By default, this cache uses the filesystem, but you can use any cache class, provided that you declare the class and its settings in the `cache` parameter. See Chapter 15 for the list of available cache storage classes. To deactivate the routing cache in production, set the `debug` parameter to `on`. 
    107107 
     108These are only the settings for the `sfPatternRouting` class. You can use another class for your application routing, either your own or one of symfony's routing factories (`sfNoRouting` and `sfPathInfoRouting`). With either of these two factories, all external URLs look like 'module/action?key1=param1'. No customization possible--but it's fast. The difference is that the first uses PHP's `GET`, and the second uses `PATH_INFO`. Use them mainly for backend interfaces. 
     109 
    108110There is one additional parameter related to routing, but this one is stored in `settings.yml`: 
    109111  * `no_script_name` enables the front controller name in generated URLs. The `no_script_name` setting can be on only for a single application in a project, unless you store the front controllers in various directories and alter the default URL rewriting rules. It is usually on for the production environment of your main application and off for the others. 
     
    117119#### Cache Settings 
    118120 
    119 Cache settings are defined in `cache.yml` for the most part, except for two in `settings.yml`: `cache` enables the template cache mechanism, and `etag` enables ETag handling on the server side (see Chapter 15). 
     121Cache settings are defined in `cache.yml` for the most part, except for two in `settings.yml`: `cache` enables the template cache mechanism, and `etag` enables ETag handling on the server side (see Chapter 15). You can also specify which storage to use for two all cache systems (the view cache, the routing cache, and the i19n cache) in `factories.yml`. Listing 19-2 show the default view cache factory configuration. 
     122 
     123Listing 19-2 - View Cache Configuration Settings, in `frontend/config/factories.yml` 
     124 
     125    view_cache: 
     126      class: sfFileCache 
     127      param: 
     128        automatic_cleaning_factor: 0 
     129        cache_dir:                 %SF_TEMPLATE_CACHE_DIR% 
     130        lifetime:                  86400 
     131        prefix:                    %SF_APP_DIR%/template 
     132 
     133The `class` can be any of `sfFileCache`, `sfAPCCache`, `sfEAcceleratorCache`, `sfXCacheCache`, `sfMemcacheCache`, and `sfSQLiteCache`. It can also be your own custom class, provided it extends `sfCache` and provides the same generic methods for setting, retrieving and deleting a key in the cache. The factory parameters depend on the class you choose, but there are constants: 
     134 
     135  * `lifetime` defines the number of seconds after which a cache part is removed 
     136  * `prefix` is a prefix added to every cache key. Use the same prefix for two applications if you want their cache to be shared. 
     137 
     138Then, for each particular factory, you have to define the location of the cache storage. 
     139 
     140 * for `sfFileCache`, the `cache_dir` parameter locates the absolute path to the cache directory 
     141 * `sfAPCCache`, `sfEAcceleratorCache`, and `sfXCacheCache` don't take any location parameter, since they use PHP native functions for communicating with APC, EAccelerator or the XCache cache systems 
     142 * for `sfMemcacheCache`, enter the hostname of the Memcached server in the `host` parameter, or an array of hosts in the `servers` parameter 
     143 * for `sfSQLiteCache`, the absolute path to the SQLite database file should be entered in the `database` parameter 
     144  
     145For additional parameters, check the API documentation of each cache class. 
     146 
     147The view is not the only component to be able to use a cache. Both the `routing` and the `I18N` factories offer a `cache` parameter in which you can set any cache factory, just like the view cache. For instance, Listing 19-1 shows of the routing uses the file cache for its speedup tactics by default, but you can change it to whatever you want. 
    120148 
    121149#### Logging Settings 
     
    150178#### Miscellaneous Configuration 
    151179 
    152 The `settings.yml` file contains a few more parameters, used internally by symfony for core behaviors. Listing 19-2 lists them as they appear in the configuration file. 
    153  
    154 Listing 19-2 - Miscellaneous Configuration Settings, in `frontend/config/settings.yml` 
     180The `settings.yml` file contains a few more parameters, used internally by symfony for core behaviors. Listing 19-3 lists them as they appear in the configuration file. 
     181 
     182Listing 19-3 - Miscellaneous Configuration Settings, in `frontend/config/settings.yml` 
    155183 
    156184    # Remove comments in core framework classes as defined in the core_compile.yml 
     
    196224There is no `autoload.yml` file in the default application configuration directory. If you want to modify the framework settings--for instance, to autoload classes stored somewhere else in your file structure--create an empty autoload.yml file and override the settings of `$sf_symfony_data_dir/config/autoload.yml` or add your own. 
    197225 
    198 The autoload.yml file must start with an autoload: key and list the locations where symfony should look for classes. Each location requires a label; this gives you the ability to override symfony's entries. For each location, provide a `name` (it will appear as a comment in `config_autoload.yml.php`) and an absolute `path`. Then define if the search must be `recursive`, which directs symfony to look in all the subdirectories for `.php` files, and `exclude` the subdirectories you want. Listing 19-3 shows the locations used by default and the file syntax. 
    199  
    200 Listing 19-3 - Default Autoloading Configuration, in `$sf_symfony_data_dir/config/autoload.yml` 
     226The autoload.yml file must start with an autoload: key and list the locations where symfony should look for classes. Each location requires a label; this gives you the ability to override symfony's entries. For each location, provide a `name` (it will appear as a comment in `config_autoload.yml.php`) and an absolute `path`. Then define if the search must be `recursive`, which directs symfony to look in all the subdirectories for `.php` files, and `exclude` the subdirectories you want. Listing 19-4 shows the locations used by default and the file syntax. 
     227 
     228Listing 19-4 - Default Autoloading Configuration, in `$sf_symfony_data_dir/config/autoload.yml` 
    201229 
    202230    autoload: 
     
    292320### The Basic File Structure 
    293321 
    294 The path variables are defined in the `$sf_symfony_data_dir/config/constants.php` file, included when the application bootstraps. These variables are stored in the `sfConfig` object, and so they are easy to override. Listing 19-4 shows a listing of the path variables and the directory they reference. 
    295  
    296 Listing 19-4 - Default File Structure Variables, from `$sf_symfony_data_dir/config/constants.php` 
     322The path variables are defined in the `$sf_symfony_data_dir/config/constants.php` file, included when the application bootstraps. These variables are stored in the `sfConfig` object, and so they are easy to override. Listing 19-5 shows a listing of the path variables and the directory they reference. 
     323 
     324Listing 19-5 - Default File Structure Variables, from `$sf_symfony_data_dir/config/constants.php` 
    297325 
    298326    sf_root_dir           # myproject/ 
     
    326354Every path to a key directory is determined by a parameter ending with `_dir`. Always use the path variables instead of real (relative or absolute) file paths, so that you will be able to change them later, if necessary. For instance, when you want to move a file to the `uploads/` directory in an application, you should use `sfConfig::get('sf_upload_dir')` for the path instead of `SF_ROOT_DIR.'/web/uploads/'`. 
    327355 
    328 The module directory structure is defined at runtime, when the routing system determines the module name (`$module_name`). It is automatically built according to the path names defined in the `constants.php` file, as shown in Listing 19-5
    329  
    330 Listing 19-5 - Default Module File Structure Variables 
     356The module directory structure is defined at runtime, when the routing system determines the module name (`$module_name`). It is automatically built according to the path names defined in the `constants.php` file, as shown in Listing 19-6
     357 
     358Listing 19-6 - Default Module File Structure Variables 
    331359 
    332360    sf_app_module_dir                 # modules/ 
     
    361389### Modifying the Project Web Root 
    362390 
    363 All the paths built in `constants.php` rely on the project root directory, which is a constant defined in the front controller (`SF_ROOT_DIR`). Usually, the root directory is one level above the `web/` directory, but you can use a different structure. Suppose that your main directory structure is made of two directories, one public and one private, as shown in Listing 19-6. This typically happens when hosting a project on a shared host. 
    364  
    365 Listing 19-6 - Example of Custom Directory Structure for a Shared Host 
     391All the paths built in `constants.php` rely on the project root directory, which is a constant defined in the front controller (`SF_ROOT_DIR`). Usually, the root directory is one level above the `web/` directory, but you can use a different structure. Suppose that your main directory structure is made of two directories, one public and one private, as shown in Listing 19-7. This typically happens when hosting a project on a shared host. 
     392 
     393Listing 19-7 - Example of Custom Directory Structure for a Shared Host 
    366394 
    367395    symfony/    # Private area 
     
    391419### Linking to Symfony Libraries 
    392420 
    393 The paths to the framework files are defined in the project `config.php` file, as you can see in Listing 19-7
    394  
    395 Listing 19-7 - The Paths to the Framework Files, in `myproject/config/config.php` 
     421The paths to the framework files are defined in the project `config.php` file, as you can see in Listing 19-8
     422 
     423Listing 19-8 - The Paths to the Framework Files, in `myproject/config/config.php` 
    396424 
    397425    [php] 
     
    443471### Default Configuration Handlers 
    444472 
    445 The default handler configuration is stored in `$sf_symfony_data_dir/config/config_handlers.yml`. This file links the handlers to the configuration files according to a file path. Listing 19-8 shows an extract of this file. 
    446  
    447 Listing 19-8 - Extract of `$sf_symfony_data_dir/config/config_handlers.yml` 
     473The default handler configuration is stored in `$sf_symfony_data_dir/config/config_handlers.yml`. This file links the handlers to the configuration files according to a file path. Listing 19-9 shows an extract of this file. 
     474 
     475Listing 19-9 - Extract of `$sf_symfony_data_dir/config/config_handlers.yml` 
    448476 
    449477    config/settings.yml: 
     
    486514If you feel like writing your own configuration handler, follow the example of the structure used by the framework in the `$sf_symfony_lib_dir/config/` directory. 
    487515 
    488 Let's suppose that your application contains a `myMapAPI` class, which provides an interface to a third-party web service delivering maps. This class needs to be initialized with a URL and a user name, as shown in Listing 19-9
    489  
    490 Listing 19-9 - Example of Initialization of the `myMapAPI` Class 
     516Let's suppose that your application contains a `myMapAPI` class, which provides an interface to a third-party web service delivering maps. This class needs to be initialized with a URL and a user name, as shown in Listing 19-10
     517 
     518Listing 19-10 - Example of Initialization of the `myMapAPI` Class 
    491519 
    492520    [php] 
     
    501529      user: foobar 
    502530 
    503 In order to transform these settings into code equivalent to Listing 19-8, you must build a configuration handler. Each configuration handler must extend `sfConfigHandler` and provide an `execute()` method, which expects an array of file paths to configuration files as a parameter, and must return data to be written in a cache file. Handlers for YAML files should extend the `sfYamlConfigHandler` class, which provides additional facilities for YAML parsing. For the `map.yml` file, a typical configuration handler could be written as shown in Listing 19-10
    504  
    505 Listing 19-10 - A Custom Configuration Handler, in `frontend/lib/myMapConfigHandler.class.php` 
     531In order to transform these settings into code equivalent to Listing 19-9, you must build a configuration handler. Each configuration handler must extend `sfConfigHandler` and provide an `execute()` method, which expects an array of file paths to configuration files as a parameter, and must return data to be written in a cache file. Handlers for YAML files should extend the `sfYamlConfigHandler` class, which provides additional facilities for YAML parsing. For the `map.yml` file, a typical configuration handler could be written as shown in Listing 19-11
     532 
     533Listing 19-11 - A Custom Configuration Handler, in `frontend/lib/myMapConfigHandler.class.php` 
    506534 
    507535    [php] 
     
    575603------------------------ 
    576604 
    577 In order to have a PHP environment compatible with the rules and best practices of agile development, symfony checks and overrides a few settings of the `php.ini` configuration. This is the purpose of the `php.yml` file. Listing 19-11 shows the default `php.yml` file. 
    578  
    579 Listing 19-11 - Default PHP Settings for Symfony, in `$sf_symfony_data_dir/config/php.yml` 
     605In order to have a PHP environment compatible with the rules and best practices of agile development, symfony checks and overrides a few settings of the `php.ini` configuration. This is the purpose of the `php.yml` file. Listing 19-12 shows the default `php.yml` file. 
     606 
     607Listing 19-12 - Default PHP Settings for Symfony, in `$sf_symfony_data_dir/config/php.yml` 
    580608 
    581609    set: