New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: CDbCacheDependency with reuseDependentData did not invalidate cache when getting cache across different requests #2290

Merged
merged 13 commits into from Apr 12, 2013

Add Unit test for reusableData test, see #2290

  • Loading branch information...
marcovtwout committed Apr 4, 2013
commit 13192086a8482b7be419e4652b8b857db4e7e0e1
@@ -34,9 +34,49 @@ public function testReusable()
$dependency3 = new MockDirectoryCacheDependency(dirname($tempFile));
$dependency3->reuseDependentData = true;
$dependency3->evaluateDependency();
$this->assertTrue($dependency3->getHasChanged());
// Behavior is slightly modified after patching CCacheDependency, but in my opinion, correctly.
//
// Before: after calling evaluateDependency(), hasChanged() would keep returning 'true',
// as $_reusableData' also stored the result of the comparison.
//
// Now: since the dependency data is always compared to the stored value in $_reusableData, after calling evaluateDependency(),
// hasChanged() will return 'false'.
//$this->assertTrue($dependency3->getHasChanged());
$this->assertFalse($dependency3->getHasChanged());
$this->assertEquals(1,MockDirectoryCacheDependency::$generateDependentDataCalled);
}
/**
* @note This test requires CCacheDependency::$_reusableData to be made public.
*/
public function testReusableWithStoredDependencies()
{
$stateName = 'test';
$storedValue = 500;
Yii::app()->setGlobalState($stateName, $storedValue);
$dependency = new CGlobalStateCacheDependency($stateName);
$dependency->reuseDependentData = true;
$fileCache = new CFileCache;
$fileCache->set('foo', $storedValue, 0, $dependency);
$fileCache->set('bar', $storedValue, 0, $dependency);
$this->assertTrue($fileCache->get('foo')==$storedValue);
/** NEW REQUEST **/
CGlobalStateCacheDependency::$_reusableData=array(); // reset $_reusableData
Yii::app()->setGlobalState($stateName, $storedValue+1); // changing state should invalidate cache
$this->assertFalse($fileCache->get('foo'));
$fileCache->set('foo', $storedValue+1, 0, $dependency); // update cache with new value
/** NEW REQUEST **/
CGlobalStateCacheDependency::$_reusableData=array(); // reset $_reusableData
$this->assertTrue($fileCache->get('foo')==$storedValue+1);
$this->assertFalse($fileCache->get('bar')); // this should be invalidated
}
}
class MockFileCacheDependency extends CFileCacheDependency
ProTip! Use n and p to navigate between commits in a pull request.