Skip to content
This repository
Browse code

Element cache filename now properly includes extra param names passed…

… along with 'cache' => true option. Fixes #2356
  • Loading branch information...
commit 850a33dba4616c355fd63da013f636d73100c617 1 parent 6836ce5
ADmad authored December 10, 2011
14  cake/libs/view/view.php
@@ -163,7 +163,7 @@ class View extends Object {
163 163
  * @access public
164 164
  */
165 165
 	var $subDir = null;
166  
-	
  166
+
167 167
 /**
168 168
  * Theme name.
169 169
  *
@@ -357,9 +357,11 @@ function element($name, $params = array(), $loadHelpers = false) {
357 357
 			if (is_array($params['cache'])) {
358 358
 				$expires = $params['cache']['time'];
359 359
 				$key = Inflector::slug($params['cache']['key']);
360  
-			} elseif ($params['cache'] !== true) {
361  
-				$expires = $params['cache'];
  360
+			} else {
362 361
 				$key = implode('_', array_keys($params));
  362
+				if ($params['cache'] !== true) {
  363
+					$expires = $params['cache'];
  364
+				}
363 365
 			}
364 366
 
365 367
 			if ($expires) {
@@ -503,7 +505,7 @@ function renderLayout($content_for_layout, $layout = null) {
503 505
 	}
504 506
 
505 507
 /**
506  
- * Fire a callback on all loaded Helpers. All helpers must implement this method, 
  508
+ * Fire a callback on all loaded Helpers. All helpers must implement this method,
507 509
  * it is not checked before being called.  You can add additional helper callbacks in AppHelper.
508 510
  *
509 511
  * @param string $callback name of callback fire.
@@ -526,7 +528,7 @@ function _triggerHelpers($callback) {
526 528
 	}
527 529
 
528 530
 /**
529  
- * Render cached view. Works in concert with CacheHelper and Dispatcher to 
  531
+ * Render cached view. Works in concert with CacheHelper and Dispatcher to
530 532
  * render cached view files.
531 533
  *
532 534
  * @param string $filename the cache file to include
@@ -866,7 +868,7 @@ function _getViewFileName($name = null) {
866 868
 			}
867 869
 		}
868 870
 		$paths = $this->_paths(Inflector::underscore($this->plugin));
869  
-		
  871
+
870 872
 		$exts = $this->_getExtensions();
871 873
 		foreach ($exts as $ext) {
872 874
 			foreach ($paths as $path) {
18  cake/tests/cases/libs/view/view.test.php
@@ -474,10 +474,10 @@ function testAddInlineScripts() {
474 474
 	function testElement() {
475 475
 		$result = $this->View->element('test_element');
476 476
 		$this->assertEqual($result, 'this is the test element');
477  
-		
  477
+
478 478
 		$result = $this->View->element('plugin_element', array('plugin' => 'test_plugin'));
479 479
 		$this->assertEqual($result, 'this is the plugin element using params[plugin]');
480  
-		
  480
+
481 481
 		$this->View->plugin = 'test_plugin';
482 482
 		$result = $this->View->element('test_plugin_element');
483 483
 		$this->assertEqual($result, 'this is the test set using View::$plugin plugin element');
@@ -558,6 +558,14 @@ function testElementCache() {
558 558
 		$this->assertTrue($cached);
559 559
 
560 560
 		$cached = false;
  561
+		$result = $View->element($element, array('cache' => true, 'param' => 'val'));
  562
+		if (file_exists(CACHE . 'views' . DS . 'element_cache_param_'.$element)) {
  563
+			$cached = true;
  564
+			unlink(CACHE . 'views' . DS . 'element_cache_param_'.$element);
  565
+		}
  566
+		$this->assertTrue($cached);
  567
+
  568
+		$cached = false;
561 569
 		$result = $View->element($element, array('cache'=>'+1 second', 'other_param'=> true, 'anotherParam'=> true));
562 570
 		if (file_exists(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element)) {
563 571
 			$cached = true;
@@ -947,7 +955,7 @@ function testSet() {
947 955
 
948 956
 		$View->set(array('key3' => 'value3'));
949 957
 		$this->assertIdentical($View->getVar('key3'), 'value3');
950  
-		
  958
+
951 959
 		$View->viewVars = array();
952 960
 		$View->set(array(3 => 'three', 4 => 'four'));
953 961
 		$View->set(array(1 => 'one', 2 => 'two'));
@@ -970,7 +978,7 @@ function testEntityReference() {
970 978
 		$View->association = 'Comment';
971 979
 		$View->field = 'user_id';
972 980
 		$this->assertEqual($View->entity(), array('Comment', 'user_id'));
973  
-		
  981
+
974 982
 		$View->model = 0;
975 983
 		$View->association = null;
976 984
 		$View->field = 'Node';
@@ -978,7 +986,7 @@ function testEntityReference() {
978 986
 		$View->entityPath = '0.Node.title';
979 987
 		$expected = array(0, 'Node', 'title');
980 988
 		$this->assertEqual($View->entity(), $expected);
981  
-		
  989
+
982 990
 		$View->model = 'HelperTestTag';
983 991
 		$View->field = 'HelperTestTag';
984 992
 		$View->modelId = null;

0 notes on commit 850a33d

Please sign in to comment.
Something went wrong with that request. Please try again.