From f45cd228f94c9653e198d3ccd99b87a73e66071e Mon Sep 17 00:00:00 2001 From: Bill Amberg Date: Tue, 22 Jun 2021 09:40:53 -0400 Subject: [PATCH] Get cache for Django>=3.2 --- dbtemplates/utils/cache.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index 98f63f7..53f0078 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -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