Issues with DboSource::$methodCache
Reported by Anthony | June 28th, 2010 @ 10:55 PM | in 1.3.2
We are using Cake 1.3 final and have been trying to get to the bottom of a bug in our app for weeks. There is a script in which we do hundreds of thousands of queries, and every so often, completely nonsensical WHERE condition strings show up in a query - ones that seem like they belong in a different query. This is despite the fact that our logic uses the correct conditions in Model::find().
Finally, we were able to trace it back to the $methodCache in DboSource. As it turns out, the DboSource analyzes the conditions, generates a hash key using crc32(), and sets the value equal to the processed condition string. If new conditions match the hash, it outputs the processed condition string, rather than rebuilding it from scratch. The problem is, crc32() isn't always unique, and for scripts with many queries, collisions are possible, as evidenced in our app.
Now, I realize this can potentially be classified as a feature, seeing as how crc32() is fast, and there is a way to manually disable method caching if you desire. However, I don't believe it's documented, and this potential issue isn't really explained in any capacity.
So I propose 1 of 2 solutions:
1. The documentation should warn developers about this potential
pitfall
2. The code should be updated to use a hashing method that's
guaranteed unique, and thus avoid the issue in the first place
Comments and changes to this ticket
-

Mark Story June 29th, 2010 @ 05:07 PM
- → Tag set to dbosource, documentation, methodcache
- → Assigned user set to Mark Story
- → Milestone set to 1.3.2
I think documentation is a good approach. Fully unique hashes can be slower than crc32 which is why it was chosen. Disabling the cache when its not helpful and providing good documentation on how to do that is probably more pertinent.
-

CakePHP June 30th, 2010 @ 07:53 AM
- → State changed from new to resolved
(from [e023350af57e07ac3351ab86c07361697fc1b369]) Updating API docs related to DboSource::$cacheMethods. Fixes #870 http://github.com/cakephp/cakephp/commit/e023350af57e07ac3351ab86c0...
-

johnnymoped August 21st, 2010 @ 04:39 PM
Sorry for hijacking this bugreport, but I ran into the same problem and couldn't find help anywhere.
Is there a way to disable the methodCache (setting $cacheMethods to false) from within a cake shell?
I tried the following (on cake 1.3.3), but without success:class MyShell extends Shell
{var $uses = array(....); function initialize() { App::import("Core","ConnectionManager"); $db =&ConnectionManager::getDataSource('local'); $db->cacheMethods = false; parent::initialize(); } function main() { .... } -

ADmad August 21st, 2010 @ 04:51 PM
Well this is still a bug tracker not a help forum. Post your question on cakeqs.org or cake-php google group.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/cakephp/cakephp
Creating a bug report
When creating a bug report, please include as much relevant information as possible. Please include code to reproduce the issue. Or even better, make a unit test. Either change an existing test or add a new test to show that the expected behavior is not occuring.
People watching this ticket
Referenced by
-
#870 Issues with DboSource::$methodCache
(from [e023350af57e07ac3351ab86c07361697fc1b369])
Updatin...