From 2b69a9a541703bc713fda228bef9541f06bede13 Mon Sep 17 00:00:00 2001 From: Mad Price Ball Date: Thu, 16 Sep 2021 15:23:39 -0700 Subject: [PATCH] Update memcache settings Updated to reflect current recommendations for Memcachier on Heroku. It's unclear whether this was necessary (but it works); an error on deploy may have been due to some other configuration issue. --- open_humans/settings.py | 33 ++++++++++++++++++--------------- requirements.in | 3 +-- requirements.txt | 13 +++++++------ 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/open_humans/settings.py b/open_humans/settings.py index 5fa31b5ba..f07299636 100644 --- a/open_humans/settings.py +++ b/open_humans/settings.py @@ -449,28 +449,31 @@ def to_bool(env, default="false"): SITE_ID = 1 + # This way of setting the memcache options is advised by MemCachier here: # https://devcenter.heroku.com/articles/memcachier#django if ENV in ["production", "staging"]: - memcache_servers = os.getenv("MEMCACHIER_SERVERS", "").replace(",", ";") + memcache_servers = os.getenv("MEMCACHIER_SERVERS", None) + memcache_username = os.getenv("MEMCACHIER_USERNAME", None) + memcache_password = os.getenv("MEMCACHIER_PASSWORD", None) - memcache_username = os.getenv("MEMCACHIER_USERNAME") - memcache_password = os.getenv("MEMCACHIER_PASSWORD") + if memcache_servers and memcache_username and memcache_password: + CACHES = { + "default": { + # Use django-bmemcached + "BACKEND": "django_bmemcached.memcached.BMemcached", - if memcache_servers: - os.environ["MEMCACHE_SERVERS"] = memcache_servers + # TIMEOUT is default expiration for keys; None disables expiration. + "TIMEOUT": None, - if memcache_username and memcache_password: - os.environ["MEMCACHE_USERNAME"] = memcache_username - os.environ["MEMCACHE_PASSWORD"] = memcache_password + "LOCATION": memcache_servers, -CACHES = { - "default": { - "BACKEND": "django_pylibmc.memcached.PyLibMCCache", - "BINARY": True, - "OPTIONS": {"ketama": True, "tcp_nodelay": True}, - } -} + "OPTIONS": { + "username": memcache_username, + "password": memcache_password, + } + } + } if DISABLE_CACHING: CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}} diff --git a/requirements.in b/requirements.in index 51d9cc40e..8f45d2886 100644 --- a/requirements.in +++ b/requirements.in @@ -14,6 +14,7 @@ dj-database-url Django==2.2.13 django-appconf django-autoslug +django-bmemcached django-bootstrap-pagination django-cors-headers django-debug-toolbar @@ -23,7 +24,6 @@ django-forms-bootstrap django-heroku django-ipware django-oauth-toolkit -django-pylibmc django-recaptcha django-storages django-waffle @@ -39,7 +39,6 @@ mailchimp Markdown mock Pillow # for sorl-thumbnail -pylibmc==1.5.2 # Note that memcache on heroku doesn't like the new version, so lock it here. pyparsing raven redis diff --git a/requirements.txt b/requirements.txt index 2a0480de5..4bc9536c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -74,6 +74,8 @@ django-appconf==1.0.4 # via -r requirements.in django-autoslug==1.9.7 # via -r requirements.in +django-bmemcached==0.3.0 + # via -r requirements.in django-bootstrap-pagination==1.7.1 # via -r requirements.in django-cors-headers==3.2.1 @@ -98,8 +100,6 @@ django-ipware==2.1.0 # via -r requirements.in django-oauth-toolkit==1.3.2 # via -r requirements.in -django-pylibmc==0.6.1 - # via -r requirements.in django-recaptcha==2.0.6 # via -r requirements.in django-storages==1.9.1 @@ -164,12 +164,10 @@ pycparser==2.20 # via cffi pyjwt[crypto]==1.7.1 # via django-allauth -pylibmc==1.5.2 - # via - # -r requirements.in - # django-pylibmc pyparsing==2.4.7 # via -r requirements.in +python-binary-memcached==0.30.1 + # via django-bmemcached python-dateutil==2.8.1 # via # arrow @@ -208,6 +206,7 @@ six==1.14.0 # django-extensions # django-waffle # env-tools + # python-binary-memcached # python-dateutil # tini sorl-thumbnail==12.6.3 @@ -224,6 +223,8 @@ text-unidecode==1.3 # via faker tini==3.0.1 # via env-tools +uhashring==2.1 + # via python-binary-memcached urllib3==1.25.9 # via # botocore