Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily Disabling Django Caching

Tags:

python

django

How do you disable Django caching on a per checkout basis?

Back before Django 1.3, I could disable caching for my local development checkout by specifying CACHE_BACKEND = None, in a settings_local.py imported by settings.py. The settings_local.py was ignored by SVN, so I could always ensure my local environment didn't cache, while not have to worry about modifying the cache params in settings.py.

Now, with Django 1.3, and the new CACHES = {...} structure, setting CACHES = None or CACHES['default']['BACKEND'] = None causes Django to choke, and setting CACHES = {} still seems to enable basic caching.

like image 831
Cerin Avatar asked Sep 29 '11 20:09

Cerin


People also ask

How do I disable caching in Django?

Back before Django 1.3, I could disable caching for my local development checkout by specifying CACHE_BACKEND = None , in a settings_local.py imported by settings.py.

Does Django automatically cache?

Local Memory Cache Unless we explicitly specify another caching method in our settings file, Django defaults to local memory caching. As its name implies, this method stores cached data in RAM on the machine where Django is running. Local memory caching is fast, responsive, and thread-safe.

Is Django cache thread-safe?

Django relies on the cache backend to be thread-safe, and a single instance of a memcache. Client is not thread-safe. The issue is with Django only creating a single instance that is shared between all threads (django. core.

What is simple caching in Django?

Django comes with its own caching system that lets you save your dynamic pages, to avoid calculating them again when needed. The good point in Django Cache framework is that you can cache − The output of a specific view. A part of a template. Your entire site.


2 Answers

Dummy Caching (for development) - this implements the cache interface, but doesn't actually cache so you could have it on your development/testing site to reduce caching and also prevent errors from caching, if those should arise.

Finally, Django comes with a "dummy" cache that doesn't actually cache – it just implements the cache interface without doing anything.

This is useful if you have a production site that uses heavy-duty caching in various places but a development/test environment where you don’t want to cache and don’t want to have to change your code to special-case the latter. To activate dummy caching, set BACKEND like so:

CACHES = {     'default': {         'BACKEND': 'django.core.cache.backends.dummy.DummyCache',     } } 
like image 158
Furbeenator Avatar answered Sep 24 '22 10:09

Furbeenator


I use this in my settings, so it's a bit more flexible i case I do want to test the usage of the deployed caching (in this case memcache)

TEST_MEMCACHE = False if not DEBUG or TEST_MEMCACHE:     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 42
michel.iamit Avatar answered Sep 21 '22 10:09

michel.iamit