title: Django and python memcached and session engine
body: <p>I have a question about setting cache with memcached in a django project.</p>
  
  <p>in settings.py file i have:</p>
  
  <pre><code>CACHES = {
  'default': {
      'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
      'LOCATION': '127.0.0.1:11211',
      'TIMEOUT': 120
   }
  }
  </code></pre>
  
  <p><strong>it works but the default session_engine in django is <em>django.contrib.sessions.backends.db</em></strong>  but when i change the setting to <strong><em>django.contrib.sessions.backends.cache</em></strong> i have the following error:</p>
  
  <pre><code> The request's session was deleted before the request completed
  </code></pre>
  
  <p>The version of django that i use is django 1.11</p>
  
  <p>i searched the community about similar questions but i couldn't figure out a solution</p>
  
  <p>When i use the setting : <strong><em>django.contrib.sessions.backends.cached_db</em></strong> it works but then again it use a table in database if i understand correctly.</p>
  
  <p>Also an other error that i get is:</p>
  
  <pre><code>The request's session was deleted before the request completed.
  The user may have logged out in a concurrent request, for example.
  </code></pre>
  
  <p>Well to answer my question (through trial and error): </p>
  
  <p>From the django docs <a href="https://docs.djangoproject.com/en/2.1/topics/http/sessions/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/2.1/topics/http/sessions/</a></p>
  
  <pre><code>Set SESSION_ENGINE to "django.contrib.sessions.backends.cache" for a
  simple caching session store. Session data will be stored directly in your    
  cache. However, session data may not be persistent: cached data can be 
   evicted if the cache fills up or if the cache server is restarted.
  
  For persistent, cached data, set SESSION_ENGINE to 
  "django.contrib.sessions.backends.cached_db". This uses a write-through 
  cache – every write to the cache will also be written to the database.
  Session reads only use the database if the data is not already in the    
  cache.
  </code></pre>
  
  <p>so the final settings for memcached that i use:</p>
  
  <pre><code>SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
  SESSION_CACHE_ALIAS = "default"
  
  CACHES = {
  'default': {
      'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
      'LOCATION': '127.0.0.1:11211',
      'TIMEOUT': 120
  }
  </code></pre>
  
  <p>}</p>