ZF-5034: Cache adapters should discard unrecognized options silently

Description

Caching strategies often differ between development, testing, and production. However, it's convenient to utilize Zend_Config's inheritance features to define cache configuration. As an example:


[production]
cache.backendName = "File"
cache.frontendName = "Core"
cache.frontendOptions.caching = false
cache.frontendOptions.lifetime = 900
cache.frontendOptions.automatic_serialization = true
cache.frontendOptions.automatic_cleaning_factor = 20
cache.backendOptions.cache_dir = APPLICATION_PATH "/../data/cache/files"
cache.backendOptions.read_control = false
cache.backendOptions.file_name_prefix = "cache"

[development : production]
cache.frontendOptions.caching = false
cache.backendName = "Sqlite"
cache.backendOptions.cache_db_complete_path = APPLICATION_PATH "/../data/cache/cache-dev.db"
cache.backendOptions.automatic_vacuum_factor = 20

[testing : production]
cache.frontendOptions.caching = false
cache.backendName = "Sqlite"
cache.backendOptions.cache_db_complete_path = APPLICATION_PATH "/../data/cache/cache-test.db"
cache.backendOptions.automatic_vacuum_factor = 20

For example, in production, I want to use a file based cache strategy, as performance benchmarks have shown it to be faster than Sqlite; in development, I use Sqlite, as performance isn't a concern and I want an easy way to inspect the cache. However, when I call Zend_Cache::factory(), an exception is raised in development -- because the backend adapter does not recognize the "cache_dir" option (inherited from the production settings).

This is poor behavior on the part of Zend_Cache; unrecognized options should simply be ignored.

Comments

Fixed in trunk in r12796, and merged to 1.7 release branch with r12797.

hum... maybe a little fast ?

IMHO, this is also a good thing to have a clear error with you make an error with an option name ?

Maybe, a good solution would be to have an option to choose the behaviour ?

No, should not be optional. This change is to make Zend_Cache behave consistently with other ZF components, which all silently ignore unrecognized options.

As noted, this becomes very problematic when using Zend_Config to setup your Zend_Cache objects, as you may have different strategies based on environment. Considering that using Zend_Config with sections and inheritance is promoted as a best practice, Zend_Cache needs to play nice.