reload_module no longer works when using caches["default"] instead of cache

6 views
Skip to first unread message

Shawn Milochik

unread,
Aug 10, 2015, 3:36:25 PM8/10/15
to django...@googlegroups.com
TL;DR; How do you modify cache settings during testing? Specifically, enable/disable (by making TIMEOUT zero or non-zero).

Full question:

I had some code that looked like this:

from django.core.cache import cache
data = cache.get(key, {})
etc.

Now it looks like this:

from django.core.cache import caches
data = caches["default"].get(key, {})
etc.

The problem is that I have tests that change the TIMEOUT cache setting and then reload the
module, using six.moves.reload_module. After making the change, the reload never works. The
timeout remains the same as it is in the settings.py file.

The reason for the change is that I've been asked to use another cache (other than default) for the
caching for this section of the app. The Django docs say that "import cache" is deprecated, and
the proper way to do it since 1.7 is to use caches. We're using Django 1.8.

The docs (https://docs.djangoproject.com/en/1.8/topics/testing/tools/#overriding-settings) say "We do not recommend altering the DATABASES setting. Altering the CACHES setting is possible," but offers no details.

Has anyone found a solution for this?
Reply all
Reply to author
Forward
0 new messages