Issues

ZF-5034: Cache adapters should discard unrecognized options silently

Issue Type: Improvement Created: 2008-11-23T07:00:12.000+0000 Last Updated: 2008-12-21T05:59:34.000+0000 Status: Resolved Fix version(s): - 1.7.1 (01/Dec/08)

Reporter: Matthew Weier O'Phinney (matthew) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Cache

Related issues: Attachments:

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:

<pre class="highlight">
[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

Posted by Matthew Weier O'Phinney (matthew) on 2008-11-24T07:36:44.000+0000

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

Posted by Fabien MARTY (fab) on 2008-11-24T10:15:32.000+0000

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 ?

Posted by Matthew Weier O'Phinney (matthew) on 2008-11-24T10:33:57.000+0000

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts