Skip to content
This repository

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

Closed
marcovtwout opened this Issue April 03, 2013 · 2 comments

2 participants

marcovtwout Paul Klimov
marcovtwout

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).

Action:

  • 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: http://pastebin.com/yD77KqK8

Is the example clear enough?

Paul Klimov
Collaborator

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

Paul Klimov
Collaborator

Resolved by commit 0adc8

Paul Klimov klimov-paul closed this April 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.