###What happened:
- [read this article](http://dev.lithify.me/lithium/wiki/blog/Lithium-0-9-5-Dont-Stop-Till-You-Get-Enough)
- loved it
- tried it and cried.
{{{
return Cache::read('default', 'spam', array('write' => function() {
return array('+1 hour' => 'spam and eggs');
}));
}}}
###What was expected:
- cache to be written and set value to be returned.
- a test case to exist
I have no filters and the `$results` is `false` (and not `null`), see: [Cache.php#151](http://dev.lithify.me/lithium/source/libraries/lithium/storage/Cache.php#151)
A test case for my problem (the same one but using `Memcache`) **lithium\tests\cases\storageCacheTest.php** {{{ public function testCacheReadThroughWriteMemcache() { $this->skipIf(!Memcache::enabled(), 'Memcache is required'); $config = array('default' => array( 'adapter' => 'Memcache', 'filters' => array() )); Cache::config($config); $result = Cache::config(); $expected = $config; $this->assertEqual($expected, $result); $write = function() { return array('+1 minute' => 'read-through write'); }; $result = Cache::read('default', 'read_through', compact('write')); $this->assertEqual('read-through write', $result); $result = Cache::read('default', 'read_through'); $this->assertEqual('read-through write', $result); $write = array('+1 minute' => 'string read-through write'); $result = Cache::read('default', 'string_read_through', compact('write')); $this->assertEqual('string read-through write', $result); $result = Cache::read('default', 'string_read_through'); $this->assertEqual('string read-through write', $result); } }}} **375.patch** a quick fix. {{{ diff --git a/libraries/lithium/storage/Cache.php b/libraries/lithium/storage/Cache.php index 1d3c3fe..345d1ba 100644 --- a/libraries/lithium/storage/Cache.php +++ b/libraries/lithium/storage/Cache.php @@ -150,11 +150,10 @@ class Cache extends \lithium\core\Adaptable { $filters = $settings[$name]['filters']; $result = static::_filter(__FUNCTION__, $params, $method, $filters); - if ($result === null && $options['write']) { + if (($result === null || $result === false) && $options['write']) { $write = (is_callable($options['write'])) ? $options['write']() : $options['write']; - list($expiry, $value) = each($write); - - return static::write($name, $key, $value, $expiry); + list($expiry, $result) = each($write); + return static::write($name, $key, $result, $expiry); } if ($options['strategies']) { }}}I still have “1” the first time. {{{ - list($expiry, $value) = each($write); + list($expiry, $result) = each($write); - return static::write($name, $key, $value, $expiry); + static::write($name, $key, $result, $expiry); }}} http://rad-dev.org/forks/greut/lithium/commits/view/adb876de87c8b72009198648309d1b8eaa0347a6#highlight I'll try to bake a test case for that.