Configuring Django Cache Machine on Heroku Memcachier? -


i use awesome cache machine django app (https://github.com/jbalogh/django-cache-machine) using memcachier on heroku.

from understand, cache machine not work out of box memcachier because memcachier requires pylibmc , sasl authentication (see https://devcenter.heroku.com/articles/memcachier#django). cache machine says supports pylibmc -- , have drop in "caching.backends.memcached.pylibmccache" caches setting.

when that, though, error: "error 47 memcached_set: server has failed , disabled until timed retry"

i thought cause of caching.backends.memcached.pylibmccache inherits django.core.cache.backends.memcached.pylibmc (see https://github.com/jbalogh/django-cache-machine/blob/master/caching/backends/memcached.py), should inherit django_pylibmc.memcached.pylibmccache in order work on heroku (but sort of shot in dark).

i made own custom cache backend instead inherited django_pylibmc.memcached.pylibmccache, when check heroku memcachier panel, doesn't appear increasing cache -- it's stuck @ 50 mb, though expect increasing each queryset.

has set cache machine on heroku? if so, how'd it?

i work memcachier. haven't dealt directly cache machine before built small app confirm works fine on heroku , memcachier.

quick background in case not familiar memcache , memcachier. there 2 protocols talking between client , server. 1 older ascii protocol , other newer binary protocol. @ memcachier support binary protocol supports authentication while ascii protocol doesn't.

the mistake making using caching.backends.memcached.pylibmccache cache backend. while pylibmc memcache client recommend supports binary protocol , sasl authentication, cache interface comes django sadly doesn't support enabling binary protocol. pylibmc goes default, ascii protocol , fails.

you can see ticket django issue here.

as such, @ memcachier we've recommended use alternative django-pylibmc-sasl package. package uses pylibmc well, provides different cache interface 1 django provides does support enabling binary protocol , authentication. discussed in our documentation here.

here code place in settings.py configure django's cache memcachier:'

## memcachier settings ## =================== def get_cache():   # complicated cache defenition on local machine (where   # memcachier_servers won't defined), try fails , use   # inbuilt local memory cache of django.   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': none,         'binary': true,         'options': {           'tcp_nodelay': true,           'no_block': true,           'tcp_keepalive': true,           '_poll_timeout': 2000,           'ketama': true,           'connect_timeout': 2000,           'remove_failed': 4,           'retry_timeout': 2,           'dead_timeout': 10         }       }     }   except:     # use django local development cache (for local development).     return {       'default': {         'backend': 'django.core.cache.backends.locmem.locmemcache'       }     }  caches = get_cache() 

this make developing on local machine easy when memcachier_servers isn't defined it'll fall django's simple local heap cache, avoiding need install memcache locally.

hope helps jake!


Comments