Issues

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

Description

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.

Comments

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

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);

I can't reproduce it.

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


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

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 :-)

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.

changed type to doc

changed in r23013