Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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 ADmad authored
Showing with 21 additions and 11 deletions.
  1. +8 −6 cake/libs/view/view.php
  2. +13 −5 cake/tests/cases/libs/view/view.test.php
View
14 cake/libs/view/view.php
@@ -163,7 +163,7 @@ class View extends Object {
* @access public
*/
var $subDir = null;
-
+
/**
* Theme name.
*
@@ -357,9 +357,11 @@ function element($name, $params = array(), $loadHelpers = false) {
if (is_array($params['cache'])) {
$expires = $params['cache']['time'];
$key = Inflector::slug($params['cache']['key']);
- } elseif ($params['cache'] !== true) {
- $expires = $params['cache'];
+ } else {
$key = implode('_', array_keys($params));
+ if ($params['cache'] !== true) {
+ $expires = $params['cache'];
+ }
}
if ($expires) {
@@ -503,7 +505,7 @@ function renderLayout($content_for_layout, $layout = null) {
}
/**
- * Fire a callback on all loaded Helpers. All helpers must implement this method,
+ * Fire a callback on all loaded Helpers. All helpers must implement this method,
* it is not checked before being called. You can add additional helper callbacks in AppHelper.
*
* @param string $callback name of callback fire.
@@ -526,7 +528,7 @@ function _triggerHelpers($callback) {
}
/**
- * Render cached view. Works in concert with CacheHelper and Dispatcher to
+ * Render cached view. Works in concert with CacheHelper and Dispatcher to
* render cached view files.
*
* @param string $filename the cache file to include
@@ -866,7 +868,7 @@ function _getViewFileName($name = null) {
}
}
$paths = $this->_paths(Inflector::underscore($this->plugin));
-
+
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
View
18 cake/tests/cases/libs/view/view.test.php
@@ -474,10 +474,10 @@ function testAddInlineScripts() {
function testElement() {
$result = $this->View->element('test_element');
$this->assertEqual($result, 'this is the test element');
-
+
$result = $this->View->element('plugin_element', array('plugin' => 'test_plugin'));
$this->assertEqual($result, 'this is the plugin element using params[plugin]');
-
+
$this->View->plugin = 'test_plugin';
$result = $this->View->element('test_plugin_element');
$this->assertEqual($result, 'this is the test set using View::$plugin plugin element');
@@ -558,6 +558,14 @@ function testElementCache() {
$this->assertTrue($cached);
$cached = false;
+ $result = $View->element($element, array('cache' => true, 'param' => 'val'));
+ if (file_exists(CACHE . 'views' . DS . 'element_cache_param_'.$element)) {
+ $cached = true;
+ unlink(CACHE . 'views' . DS . 'element_cache_param_'.$element);
+ }
+ $this->assertTrue($cached);
+
+ $cached = false;
$result = $View->element($element, array('cache'=>'+1 second', 'other_param'=> true, 'anotherParam'=> true));
if (file_exists(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element)) {
$cached = true;
@@ -947,7 +955,7 @@ function testSet() {
$View->set(array('key3' => 'value3'));
$this->assertIdentical($View->getVar('key3'), 'value3');
-
+
$View->viewVars = array();
$View->set(array(3 => 'three', 4 => 'four'));
$View->set(array(1 => 'one', 2 => 'two'));
@@ -970,7 +978,7 @@ function testEntityReference() {
$View->association = 'Comment';
$View->field = 'user_id';
$this->assertEqual($View->entity(), array('Comment', 'user_id'));
-
+
$View->model = 0;
$View->association = null;
$View->field = 'Node';
@@ -978,7 +986,7 @@ function testEntityReference() {
$View->entityPath = '0.Node.title';
$expected = array(0, 'Node', 'title');
$this->assertEqual($View->entity(), $expected);
-
+
$View->model = 'HelperTestTag';
$View->field = 'HelperTestTag';
$View->modelId = null;
Please sign in to comment.
Something went wrong with that request. Please try again.