Using Memcache in Django/Python 3,4 with Heroku
Question: I have been following [this
tutorial](https://devcenter.heroku.com/articles/django-memcache#further-
reading-and-resources) so that I can use Memcache on my app on Heroku. However
I ran into issues when using `cache.get()` in Heroku's shell (it works fine on
my end):

    
    
    File "/app/.heroku/python/lib/python3.4/site-packages/django_pylibmc/memcached.py", line 92
        except MemcachedError, e:
                         ^
    SyntaxError: invalid syntax
    

I saw [this question](http://stackoverflow.com/questions/29189899/django-
pylibmc-complains-under-django-1-7-and-python-3-4), who had the same issue as
me. My `settings.py` looked like this:

    
    
    def get_cache():
      import os
      try:
        os.environ['MEMCACHE_SERVERS'] = os.environ['MEMCACHIER_SERVERS'].replace(',', ';')
        os.environ['MEMCACHE_USERNAME'] = os.environ['MEMCACHIER_USERNAME']
        os.environ['MEMCACHE_PASSWORD'] = os.environ['MEMCACHIER_PASSWORD']
        return {
          'default': {
            'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
            'TIMEOUT': 500,
            'BINARY': True,
            'OPTIONS': { 'tcp_nodelay': True }
          }
    }
      except:
        return {
          'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
          }
    }
    

And so I replaced `django_pylibmc.memcached.PyLibMCCache` with
`django.core.cache.backends.memcached.PyLibMCCache`. However then I got a
different error when I tried `cache.get("foo")` again:

    
    
    File "/app/.heroku/python/lib/python3.4/site-packages/django/core/cache/backends/memcached.py", line 84, in get
    
    val = self._cache.get(key)
    
    _pylibmc.ConnectionError: error 3 from memcached_get(:1:foo): (0x1c4ed40) CONNECTION FAILURE,  host: localhost:11211 -> libmemcached/get.cc:314
    

Could someone help me out? Is there some settings somewhere that I need to
change?


Answer: I decided to switch to using Django's database cache instead.

