ZF-10500: Empty array isn't being stored in cache

Issue Type: Docs: Problem Created: 2010-09-27T16:41:27.000+0000 Last Updated: 2010-11-20T09:29:52.000+0000 Status: Resolved Fix version(s): - 1.11.0 (02/Nov/10)

Reporter: Mathieu Decaffmeyer (mathi) Assignee: Marc Bennewitz (private) (mabe) Tags: - Zend_Cache

Related issues: Attachments:


Empty arrays cannot be stored in cache. Though, an empty array may result from a very expensive SQL. So no matter the value of the variable that needs to be cached, it just should be cached.


Posted by Marc Bennewitz (private) (mabe) on 2010-09-29T10:36:20.000+0000

Please tell us which Backend and Frontend you are using and your configuration options

Posted by Mathieu Decaffmeyer (mathi) on 2010-09-30T04:38:51.000+0000

Hi Marc, I'm using Core File, below is my configuration :

$frontendOptions = array('lifetime' => NULL, 'automatic_serialization' => true); $backendOptions = array('cache_dir' => './tmp/', 'hashed_directory_level' => 2); $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);

Posted by Marc Bennewitz (private) (mabe) on 2010-09-30T14:11:51.000+0000

I can't reproduce it.

The following is true on my machine with your cache object:

<pre class="highlight">
$cache->save(array(), 'test');
var_dump($cache->load('test')); // displays "array(0) {}"

Can you please create a small test script and tell me your used version of ZF.

Posted by Mathieu Decaffmeyer (mathi) on 2010-09-30T15:48:45.000+0000

Marc, you are right. I took the code from the doc :

if(!$result = $cache->load('myresult')) { ... }

The empty array will of course execute the if block ... I hate loose typing :-)

Posted by Mathieu Decaffmeyer (mathi) on 2010-09-30T15:56:05.000+0000

What about changing the doc a little bit ?

$result = $cache->load('myresult'); if($result === false) { ... }

The cache could return "0", "", array(), etc. Only strictly false should be checked because only false will be return when there is no cache hit.

Posted by Marc Bennewitz (private) (mabe) on 2010-10-01T08:57:38.000+0000

changed type to doc

Posted by Marc Bennewitz (private) (mabe) on 2010-10-01T09:08:17.000+0000

changed in r23013

Have you found an issue?

See the Overview section for more details.


© 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.