mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-24 12:13:43 +00:00
Checks that the database and the cache are compatible.
This commit is contained in:
parent
8fc89836d0
commit
64650340b6
1 changed files with 37 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue