On Oct 29, 2011, at 11:14 AM, Aymeric Augustin wrote: Thank Aymeric,
> >> As an alternative, I propose we: >> >> 1. Add a new optional setting under CACHES, CLEAR_BETWEEN_TESTS. The default >> for this setting is False. To be clear, the value is set independently for >> each cache defined in CACHES. >> >> 2. Between each test, cycle through each cache in CACHES. If >> CLEAR_BETWEEN_TESTS is True, then clear() that cache. Otherwise, move on. > > Here's what cache.clear() does on each cache backend: > - db: it runs a SQL query "DELETE FROM <cache_table>" > - dummy: it's a no-op > - filebased: it calls shutil.rmtree on the cache directory > - locmem: it clears two Python dicts > - memcached: it calls the "flush_all" API method > > It's dirt cheap with locmem, who is probably the most popular cache backend > for testing. It's a little bit expensive with db, but if you're using the > database cache backend, you're clearly not a performance junkie. > > The fact that Django doesn't reset cache state between tests is a bug, which > means we don't need to be 100% backwards compatible. I'd be comfortable with > calling clear() unconditionally on each cache, after each test. I don't feel > strongly against the CLEAR_BETWEEN_TESTS flag, but if you add it, I suggest > making it True by default. > > To sum up: +1 on .clear(), -0 on CLEAR_BETWEEN_TESTS. > I *believe* that when this conversation has been had in the past, the simple solution of cache.clear() has been sort of a nonstarter. Certainly it's by far the simplest solution, and it's tolerable for most of the caches. The main issue is that, using the memcached backend, clear() flushes out the entire cache….i.e. not just the cache for the tests, not just the cache you might have set with this application, but literally the whole of the cache. So the challenge has been to find a way to clear the cache between tests without potentially destructive side effects. 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. Cheers, Jim -- 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.