Disable debug mode caching in Django

I use memcached view caching for my production servers on some very computational and DB-configured views, for example:

urlpatterns = ('',
    (r'^foo/(\d{1,2})/$', cache_page(60 * 15)(my_view)),
) 

Is there a way to disable caching when DEBUG == True in Settings.py, so I don’t have to worry about cache files with cache being cached and can use my IDE debugger?

+5
source share
1 answer

You can configure caches conditionally in settings.py, for example:

if not DEBUG:
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
            'LOCATION': '127.0.0.1:11211',
        }
    }
else:
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        }
    }
+15
source

All Articles