mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
Cleanup caching configuration
Requires Django 1.3+
This commit is contained in:
parent
47ff56cfe2
commit
95e484d073
2 changed files with 9 additions and 23 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from appconf import AppConf
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
||||
class ImageKitConf(AppConf):
|
||||
|
|
@ -17,27 +18,11 @@ class ImageKitConf(AppConf):
|
|||
|
||||
def configure_cache_backend(self, value):
|
||||
if value is None:
|
||||
# DEFAULT_CACHE_ALIAS doesn't exist in Django<=1.2
|
||||
try:
|
||||
from django.core.cache import DEFAULT_CACHE_ALIAS as default_cache_alias
|
||||
except ImportError:
|
||||
default_cache_alias = 'default'
|
||||
from django.core.cache import DEFAULT_CACHE_ALIAS
|
||||
return DEFAULT_CACHE_ALIAS
|
||||
|
||||
caches = getattr(settings, 'CACHES', None)
|
||||
if caches is None:
|
||||
# Support Django<=1.2 there is no default `CACHES` setting
|
||||
try:
|
||||
from django.core.cache.backends.dummy import DummyCache
|
||||
except ImportError:
|
||||
dummy_cache = 'dummy://'
|
||||
else:
|
||||
dummy_cache = 'django.core.cache.backends.dummy.DummyCache'
|
||||
return dummy_cache
|
||||
|
||||
if default_cache_alias in caches:
|
||||
value = default_cache_alias
|
||||
else:
|
||||
raise ValueError("The default cache alias '%s' is not available in CACHES" % default_cache_alias)
|
||||
if value not in settings.CACHES:
|
||||
raise ImproperlyConfigured("{0} is not present in settings.CACHES".format(value))
|
||||
|
||||
return value
|
||||
|
||||
|
|
|
|||
|
|
@ -148,14 +148,15 @@ def call_strategy_method(file, method_name):
|
|||
fn(file)
|
||||
|
||||
|
||||
def get_cache(backend=settings.IMAGEKIT_CACHE_BACKEND):
|
||||
def get_cache():
|
||||
try:
|
||||
from django.core.cache import caches
|
||||
except ImportError:
|
||||
# Django < 1.7
|
||||
from django.core.cache import get_cache
|
||||
return get_cache(backend)
|
||||
return get_cache(settings.IMAGEKIT_CACHE_BACKEND)
|
||||
|
||||
return caches[backend]
|
||||
return caches[settings.IMAGEKIT_CACHE_BACKEND]
|
||||
|
||||
|
||||
def sanitize_cache_key(key):
|
||||
|
|
|
|||
Loading…
Reference in a new issue