diff --git a/ansible/roles/horizon/templates/_9998-kolla-settings.py.j2 b/ansible/roles/horizon/templates/_9998-kolla-settings.py.j2
index 09119a8de121e71dfd0c556d2d94f8ae0fcea27d..66c786a73093d74fa318e43385cb3bc0601326e3 100644
--- a/ansible/roles/horizon/templates/_9998-kolla-settings.py.j2
+++ b/ansible/roles/horizon/templates/_9998-kolla-settings.py.j2
@@ -16,6 +16,9 @@ DATABASES = {
     'PORT': '{{ database_port }}'
     }
 }
+{% elif groups['memcached'] | length > 0 and not horizon_backend_database | bool %}
+SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
+CACHES['default']['LOCATION'] = [{% for host in groups['memcached'] %}'{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ memcached_port }}'{% if not loop.last %},{% endif %}{% endfor %}]
 {% endif %}
 
 {% if kolla_enable_tls_external | bool or kolla_enable_tls_internal | bool %}
@@ -39,16 +42,6 @@ OPENSTACK_KEYSTONE_DOMAIN_CHOICES = (
 LOCAL_PATH = '/tmp'
 SECRET_KEY='{{ horizon_secret_key }}'
 
-{% if groups['memcached'] | length > 0 and horizon_backend_database | bool == False %}
-SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
-CACHES = {
-    'default': {
-        'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
-        'LOCATION': [{% for host in groups['memcached'] %}'{{ 'api' | kolla_address(host) | put_address_in_context('memcache') }}:{{ memcached_port }}'{% if not loop.last %},{% endif %}{% endfor %}]
-    }
-}
-{% endif %}
-
 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
 
 {% if multiple_regions_names|length > 1 %}