Making cacheAction array settings use action names instead of url paths. This removes the ability to set different durations for specific passed arguments. However, makes passed args, named params, and querystring params all behave the same in regard to cacheAction. Test cases updated.

This commit is contained in:
Mark Story 2009-12-28 21:26:51 -05:00
parent 45a3eb250f
commit 6749e1166b
2 changed files with 33 additions and 42 deletions

View file

@ -70,19 +70,15 @@ class CacheHelper extends AppHelper {
$check = Inflector::slug(Router::reverse($this->params));
$base = trim(str_replace('/', '_', $this->base), '_');
$check = trim(str_replace($base, '', $check), '_');
$match = $check;
$keys = str_replace('/', '_', array_keys($this->cacheAction));
$found = array_keys($this->cacheAction);
$keys = array_keys($this->cacheAction);
$index = null;
$count = 0;
foreach ($keys as $key => $value) {
if (strpos($check, rtrim($value, '_')) !== false) {
$index = $found[$count];
foreach ($keys as $action) {
if ($action == $this->params['action']) {
$index = $action;
break;
}
$count++;
}
if (!isset($index) && $this->action == 'index') {
@ -92,19 +88,17 @@ class CacheHelper extends AppHelper {
$options = $this->cacheAction;
if (isset($this->cacheAction[$index])) {
if (is_array($this->cacheAction[$index])) {
$options = array_merge(array('duration'=> 0, 'callbacks' => false), $this->cacheAction[$index]);
$options = array_merge(array('duration' => 0, 'callbacks' => false), $this->cacheAction[$index]);
} else {
$cacheTime = $this->cacheAction[$index];
}
}
if (array_key_exists('duration', $options)) {
if (isset($options['duration'])) {
$cacheTime = $options['duration'];
}
if (array_key_exists('callbacks', $options)) {
if (isset($options['callbacks'])) {
$useCallbacks = $options['callbacks'];
}
} else {
$cacheTime = $this->cacheAction;
}

View file

@ -17,9 +17,6 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
App::import('Core', array('Controller', 'Model', 'View'));
App::import('Helper', 'Cache');
@ -344,7 +341,7 @@ class CacheHelperTest extends CakeTestCase {
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array(
'cache_parsing/' => 21600
'cache_parsing' => 21600
);
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
@ -360,30 +357,6 @@ class CacheHelperTest extends CakeTestCase {
@unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(33),
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing/33' => 21600
);
$this->Controller->here = '/cacheTest/cache_parsing/33';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing_33.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
@ -393,7 +366,7 @@ class CacheHelperTest extends CakeTestCase {
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing/33' => 21600
'some_other_action' => 21600
);
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
@ -416,7 +389,31 @@ class CacheHelperTest extends CakeTestCase {
function testCacheWithCustomRoutes() {
Router::reload();
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
$this->Controller->cache_parsing();
$this->Controller->params = array(
'lang' => 'en',
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->here = '/en/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'en_cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
}
/**
* testCacheEmptySections method