diff --git a/cachalot/apps.py b/cachalot/apps.py index 8efc520..7e19ef1 100644 --- a/cachalot/apps.py +++ b/cachalot/apps.py @@ -1,8 +1,45 @@ from django.apps import AppConfig +from django.conf import settings +from django.core.checks import register, Tags, Error, Warning from .monkey_patch import patch +VALID_DATABASE_ENGINES = { + 'django.db.backends.sqlite3', + 'django.db.backends.postgresql_psycopg2', + 'django.db.backends.mysql', +} + + +VALID_CACHE_BACKENDS = { + 'django.core.cache.backends.locmem.LocMemCache', + 'django.core.cache.backends.filebased.FileBasedCache', + 'django_redis.cache.RedisCache', + 'django.core.cache.backends.memcached.MemcachedCache', + 'django.core.cache.backends.memcached.PyLibMCCache', +} + + +@register(Tags.compatibility) +def check_compatibility(app_configs, **kwargs): + errors = [] + for setting, k, valid_values in ( + (settings.DATABASES, 'ENGINE', VALID_DATABASE_ENGINES), + (settings.CACHES, 'BACKEND', VALID_CACHE_BACKENDS)): + for alias, d in setting.items(): + value = d[k] + if value not in valid_values: + error_class = Error if alias == 'default' else Warning + errors.append( + error_class( + '`%s` is not compatible with django-cachalot.' % value, + id='cachalot.E001', + ) + ) + return errors + + class CachalotConfig(AppConfig): name = 'cachalot' patched = False