Skip to content

Commit

Permalink
Update memcache settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
madprime committed Sep 20, 2021
1 parent 115ba86 commit 2b69a9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
33 changes: 18 additions & 15 deletions open_humans/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
Expand Down
3 changes: 1 addition & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +24,6 @@ django-forms-bootstrap
django-heroku
django-ipware
django-oauth-toolkit
django-pylibmc
django-recaptcha
django-storages
django-waffle
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2b69a9a

Please sign in to comment.