Hi Lukasz, On Oct 30, 2011, at 3:26 AM, Łukasz Rekucki wrote:
>> If I personally were given the choice between cache.clear() and nothing at >> all, i'd take cache.clear() and be careful with it. But I'm not sure if the >> rest of the community is willing to accept such a solution. Hence the >> CLEAR_BETWEEN_TESTS flag as a compromise. > > But the flag doesn't solve the memcached issue, right? IMHO, it only > adds to the false impression that you can have any control on what > gets flushed by memcached. > > I also agree with Aymeric that not clearing cache state is a bug. > Having a flag to fix/restore buggy behaviour seems weird. I agree with this. At the same time, this line is from the Django cache docs: "Finally, if you want to delete all the keys in the cache, use cache.clear(). Be careful with this; clear() will remove everythingfrom the cache, not just the keys set by your application." We're warning people about using clear() indiscriminately, and yet we're proposing to do just that in the test suite on every test run. So although I agree that not clearing the cache between tests is a bug, I do feel like the responsible thing to do is to give developers some measure of control over this behavior. If you really really want to run the tests and you really really don't want to have your cache cleared, here's a way. Or if you're more than happy to clear the cache on your dev machines but want to have some measure of protection from a hapless developer coming along and running ./manage.py test on your production machine and thus clearing your *entire* cache, here's a way. Lukasz, as an alternative you can take a quick look at the patch I put together for #11505. This is an approach that, in a sense, creates a test namespace on each cache during tests and clears any keys set in it during the test. This approach preserves the state of each cache during the test and ensures it is restored at the end. The cost is the added degree of complexity that comes with monkeypatching systems during tests. So though in some sense it's a "better" solution, I'm not sure that the cost is worth the benefit. Anyhow, I honestly agree with you and Aymeric that a simple cache.clear() is fine, but I thought the CLEAR_BETWEEN_TESTS flag was a good way to answer any objections that we should be cautious about clearing the cache. If there are no such objections, let's just do a simple cache.clear() then. It's literally a single line of code in the test runner, along with a test and a note in the docs. I can do that work as soon as some kind of consensus is reached. Thanks for your feedback. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.