Permalink
Browse files

Make $reusableData protected instead of private, so we can reset in s…

…ubclass.
  • Loading branch information...
marcovtwout committed Apr 8, 2013
1 parent 7794bfa commit 00119b13e5c782672ffd979e313a3d911f71e861
@@ -39,7 +39,7 @@ class CCacheDependency extends CComponent implements ICacheDependency
* @var array cached data for reusable dependencies.
* @since 1.1.11
*/
private static $_reusableData=array();
protected static $reusableData=array();
private $_hash;
private $_data;
@@ -53,9 +53,9 @@ public function evaluateDependency()
if ($this->reuseDependentData)
{
$hash=$this->getHash();
if (!isset(self::$_reusableData[$hash]['dependentData']))
self::$_reusableData[$hash]['dependentData']=$this->generateDependentData();
$this->_data=self::$_reusableData[$hash]['dependentData'];
if (!isset(self::$reusableData[$hash]['dependentData']))
self::$reusableData[$hash]['dependentData']=$this->generateDependentData();
$this->_data=self::$reusableData[$hash]['dependentData'];
}
else
$this->_data=$this->generateDependentData();
@@ -69,9 +69,9 @@ public function getHasChanged()
if ($this->reuseDependentData)
{
$hash=$this->getHash();
if (!isset(self::$_reusableData[$hash]['dependentData']))
self::$_reusableData[$hash]['dependentData']=$this->generateDependentData();
return self::$_reusableData[$hash]['dependentData']!=$this->_data;
if (!isset(self::$reusableData[$hash]['dependentData']))
self::$reusableData[$hash]['dependentData']=$this->generateDependentData();
return self::$reusableData[$hash]['dependentData']!=$this->_data;
}
else
return $this->generateDependentData()!=$this->_data;
@@ -86,14 +86,6 @@ public function getDependentData()
return $this->_data;
}
/**
* @see CCacheDependencyTest
*/
public static function resetReusableData()
{
self::$_reusableData=array();
}
/**
* Generates the data needed to determine if dependency has been changed.
* Derived classes should override this method to generate actual dependent data.
@@ -23,7 +23,7 @@ public function testReuseDependentData()
$dependency2=new MockCacheDependency();
$dependency2->reuseDependentData = true;
CCacheDependency::resetReusableData();
MockCacheDependency::resetReusableData();
$this->setCacheDependentData('start');
$dependency1->evaluateDependency();
$dependency2->evaluateDependency();
@@ -32,21 +32,21 @@ public function testReuseDependentData()
$this->assertEquals(1,MockCacheDependency::$generateDependentDataCalled,'Extra invokations of "generateDependentData()"!');
// New request:
CCacheDependency::resetReusableData();
MockCacheDependency::resetReusableData();
MockCacheDependency::$generateDependentDataCalled=0;
$this->assertFalse($dependency1->getHasChanged(),'Dependency1 changed for new request!');
$this->assertFalse($dependency2->getHasChanged(),'Dependency2 changed for new request!');
$this->assertEquals(1,MockCacheDependency::$generateDependentDataCalled,'Extra invokations of "generateDependentData()"!');
// New request:
CCacheDependency::resetReusableData();
MockCacheDependency::resetReusableData();
MockCacheDependency::$generateDependentDataCalled=0;
$this->setCacheDependentData('change1');
$this->assertTrue($dependency1->getHasChanged(),'Dependency1 is not changed after source change!');
$dependency1->evaluateDependency();
// New request:
CCacheDependency::resetReusableData();
MockCacheDependency::resetReusableData();
MockCacheDependency::$generateDependentDataCalled=0;
$this->assertFalse($dependency1->getHasChanged(),'Dependency1 has been changed!');
$this->assertTrue($dependency2->getHasChanged(),'Dependency2 has not been changed!');
@@ -64,4 +64,9 @@ public function generateDependentData()
self::$generateDependentDataCalled++;
return call_user_func(self::$generateDependentDataCallback);
}
public static function resetReusableData()
{
self::$reusableData=array();
}
}

0 comments on commit 00119b1

Please sign in to comment.