Skip to content

Commit

Permalink
Use native Redis backend for Django 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
niccolomineo committed Mar 11, 2022
1 parent 3a21eb5 commit 1ad783f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions django_cache_url/__init__.py
Expand Up @@ -2,6 +2,8 @@
import os
import re

from django import VERSION

try:
import urllib.parse as urlparse
except ImportError: # python 2
Expand All @@ -25,6 +27,13 @@
DEFAULT_ENV = 'CACHE_URL'
DJANGO_REDIS_CACHE = 'redis-cache'

# TODO Remove as soon as Django 3.2 goes EOL
redis_backend = (
"django_redis.cache.RedisCache"
if VERSION[0] < 4
else "django.core.cache.backends.redis.RedisCache"
)

BACKENDS = {
'db': 'django.core.cache.backends.db.DatabaseCache',
'dummy': 'django.core.cache.backends.dummy.DummyCache',
Expand All @@ -37,9 +46,9 @@
'pymemcached': 'django.core.cache.backends.memcached.MemcachedCache',
'pymemcache': 'django.core.cache.backends.memcached.PyMemcacheCache',
DJANGO_REDIS_CACHE: 'redis_cache.RedisCache',
'redis': 'django_redis.cache.RedisCache',
'rediss': 'django_redis.cache.RedisCache',
'hiredis': 'django_redis.cache.RedisCache',
'redis': redis_backend,
'rediss': redis_backend,
'hiredis': redis_backend,
}


Expand Down

0 comments on commit 1ad783f

Please sign in to comment.