Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn caching off in debug mode in Django

Tags:

django

I am using memcached view caching for my production servers on some very computationally & DB intense views, like so:

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

Is there a way to turn caching off when DEBUG==True in Settings.py so that I don't have to worry about obselete view outputs being cached and can use my IDE's debugger?

like image 986
B Robster Avatar asked Jul 26 '12 08:07

B Robster


1 Answers

You can set up caches conditionally in your settings.py, like this:

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',
        }
    }
like image 141
che Avatar answered Oct 05 '22 23:10

che