Get cache for Django>=3.2

This commit is contained in:
Bill Amberg 2021-06-22 09:40:53 -04:00
parent 24b5f469a2
commit f45cd228f9

View file

@ -1,3 +1,4 @@
import django
from django.core import signals
from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify
@ -9,8 +10,12 @@ def get_cache_backend():
"""
Compatibilty wrapper for getting Django's cache backend instance
"""
from django.core.cache import _create_cache
cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
if django.VERSION[0] >= 3 and django.VERSION[1] >= 2:
from django.core.cache import caches
cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND)
else:
from django.core.cache import _create_cache
cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
# Some caches -- python-memcached in particular -- need to do a cleanup at
# the end of a request cycle. If not implemented in a particular backend
# cache.close is a no-op