|
3 | 3 |
|
4 | 4 | from datetime import timedelta
|
5 | 5 |
|
6 |
| -import django |
7 |
| -from django.utils.encoding import smart_str |
8 | 6 | from django.core.cache import cache, caches
|
9 | 7 |
|
10 | 8 | from celery import current_app
|
|
15 | 13 | cache = caches[current_app.conf.CELERY_CACHE_BACKEND] # noqa
|
16 | 14 |
|
17 | 15 |
|
18 |
| -class DjangoMemcacheWrapper(object): |
19 |
| - """Wrapper class to django's memcache backend class, that overrides the |
20 |
| - :meth:`get` method in order to remove the forcing of unicode strings |
21 |
| - since it may cause binary or pickled data to break.""" |
22 |
| - |
23 |
| - def __init__(self, cache): |
24 |
| - self.cache = cache |
25 |
| - |
26 |
| - def get(self, key, default=None): |
27 |
| - val = self.cache._cache.get(smart_str(key)) |
28 |
| - if val is None: |
29 |
| - return default |
30 |
| - else: |
31 |
| - return val |
32 |
| - |
33 |
| - def set(self, key, value, timeout=0): |
34 |
| - self.cache.set(key, value, timeout) |
35 |
| - |
36 |
| -# Check if django is using memcache as the cache backend. If so, wrap the |
37 |
| -# cache object in a DjangoMemcacheWrapper for Django < 1.2 that fixes a bug |
38 |
| -# with retrieving pickled data. |
39 |
| -from django.core.cache.backends.base import InvalidCacheBackendError # noqa |
40 |
| -try: |
41 |
| - from django.core.cache.backends.memcached import CacheClass |
42 |
| -except (ImportError, AttributeError, InvalidCacheBackendError): |
43 |
| - pass |
44 |
| -else: |
45 |
| - if django.VERSION[0:2] < (1, 2) and isinstance(cache, CacheClass): |
46 |
| - cache = DjangoMemcacheWrapper(cache) |
47 |
| - |
48 |
| - |
49 | 16 | class CacheBackend(KeyValueStoreBackend):
|
50 | 17 | """Backend using the Django cache framework to store task metadata."""
|
51 | 18 |
|
|
0 commit comments