Configuring the Cache

A number of configuration options give you control over how the cache is handled by your application.

First you need to set two general cache settings: where to store the front-end and back-end cache.

Next you need to set the front-end options:

• lifetime: This is the length of time that the cache will persist. This is measured in seconds and defaults to 3600 (1 hour).

• automatic_serialization: This enables you to store data in the cache that is not in string form by serializing it. It is slower but makes reading and writing to the cache easier.

On the back end, you will need to set the following settings:

• lifetime: This is the same setting as the front-end option of the same name.

• cache_dir: This is the directory that the cache files will be stored in when you use a file-based back end.

■ Note In this example, you are going to use the most common settings, but I strongly recommend reviewing the current Zend Framework documentation; a number of methods for optimizing your site caching are beyond the scope of this book.

First you need to create a folder for the cache in the root of your project named cache. Then you will add these settings to the application.ini configuration file, as shown in Listing 11-7. Zend_Application will pass these settings to your application resource, enabling you to fine-tune the cache without altering your source code.

Listing 11-7. The Cache Settings in application/configs/application.ini resources.cache.frontEnd = core resources.cache.backEnd = file resources.cache.frontEndOptions.lifetime = 1200 resources.cache.frontEndOptions.automatic_serialization = true resources.cache.backEndOptions.lifetime = 3600

resources.cache.backEndOptions.cache_dir = APPLICATION_PATH "/../cache"

Was this article helpful?

0 0

Post a comment