CDbCacheDependency with reuseDependentData will not invalidate cache in certain scenario #2289

marcovtwout opened this Issue Apr 3, 2013 · 2 comments


None yet
2 participants

marcovtwout commented Apr 3, 2013

I discovered a problem with CDbCacheDependency and reuseDependentData.
Check the following scenario:

Both foo() and bar() call getCache/setCache(), using different keys, but using the same dependency.

$dependency = new CDbCacheDependency("SELECT MAX(updatedOn) FROM Table");
$dependency->reuseDependentData = true; // execute dependency once per request

Request 1:

  • foo() calls getCache('foo'), doesn't exist, call setCache('foo', $dependency).
  • bar() calls getCache('bar'), doesn't exist, call setCache('bar', $dependency).


  • change updatedOn column value in database.

Request 2:

  • foo() calls getCache('foo'), dependency has changed, updates cache.
  • NOTE: bar() is not called.

Request 3:

  • foo() calls getCache('foo'), dependency hasn't changed, uses cached value. Sets reusableData.
  • bar() calls getCache('bar'), read from reusableData, says dependency hasn't changed, uses OLD cached value.

Solution: the dependency result still has to be compared to the cached dependency result. We simply remove the hasChanged boolean with the cached value and compare the data every time:

Is the example clear enough?


klimov-paul commented Apr 3, 2013

@marcovtwout, could you compose a Pull Request for this issue?
If you ready to do so, please read the contribution workflow first.

@ghost ghost assigned klimov-paul Apr 5, 2013


klimov-paul commented Apr 12, 2013

Resolved by commit 0adc8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment