Browse Source

This patch adds the CELERY_CACHE_BACKEND for using something other than the django-global backend.

Luis Clara Gomez 15 years ago
parent
commit
34a386d0a5
3 changed files with 22 additions and 1 deletions
  1. 6 1
      celery/backends/cache.py
  2. 11 0
      celery/conf.py
  3. 5 0
      docs/configuration.rst

+ 6 - 1
celery/backends/cache.py

@@ -1,8 +1,13 @@
 """celery.backends.cache"""
-from django.core.cache import cache
+from django.core.cache import cache, get_cache
 from django.core.cache.backends.base import InvalidCacheBackendError
 from django.utils.encoding import smart_str
 from celery.backends.base import KeyValueStoreBackend
+from celery import conf
+
+# CELERY_CACHE_BACKEND overrides the django-global(tm) backend settings.
+if conf.CELERY_CACHE_BACKEND:
+    cache = get_cache(conf.CELERY_CACHE_BACKEND)
 
 
 class DjangoMemcacheWrapper(object):

+ 11 - 0
celery/conf.py

@@ -253,3 +253,14 @@ The backend used to store the status of periodic tasks.
 CELERY_PERIODIC_STATUS_BACKEND = getattr(settings,
                                     "CELERY_PERIODIC_STATUS_BACKEND",
                                     DEFAULT_PERIODIC_STATUS_BACKEND)
+
+
+"""
+
+.. data:: CELERY_CACHE_BACKEND
+
+Use a custom cache backend for celery. If not set the django-global
+cache backend in ``CACHE_BACKEND`` will be used.
+
+"""
+CELERY_CACHE_BACKEND = getattr(settings, "CELERY_CACHE_BACKEND", None)

+ 5 - 0
docs/configuration.rst

@@ -78,6 +78,7 @@ Task result backend settings
     * mongodb
         Use MongoDB.
 
+
 Database backend settings
 =========================
 
@@ -114,6 +115,10 @@ Cache backend settings
 Please see the documentation for the Django cache framework settings:
 http://docs.djangoproject.com/en/dev/topics/cache/#memcached
 
+To use a custom cache backend for Celery, while using another for Django,
+you should use the ``CELERY_CACHE_BACKEND`` setting instead of the regular
+django ``CACHE_BACKEND`` setting.
+
 Example configuration
 ---------------------