diff --git a/config/settings/base.py b/config/settings/base.py index 69021e824..01ef65248 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -84,12 +84,16 @@ USE_TZ=(bool,True), TIME_ZONE=(str,'Canada/Pacific'), - # Database defaults: + # SQL defaults SQL_HOST = (str, 'db'), - SQL_DATABASE= (str, 'ubyssey'), + SQL_DATABASE = (str, 'ubyssey'), SQL_USER = (str, 'root'), SQL_PASSWORD = (str, 'ubyssey'), + # Redis defaults + REDIS_HOST = (str, '127.0.0.1'), + REDIS_PORT = (str, '6379'), + # Keys SECRET_KEY = (str, 'thisisakey'), NOTIFICATION_KEY= (str, 'thisisakeytoo'), @@ -115,6 +119,9 @@ ADS_TXT_URL = env('ADS_TXT_URL') ROOT_URLCONF = env('ROOT_URLCONF') +REDIS_HOST = env('REDIS_HOST') +REDIS_PORT = env('REDIS_PORT') + # Initialize the databases. # Note it should be possible to parse all this information in a single line: # DATABASES = {'default': env.db('DATABASE_URL')} diff --git a/config/settings/production.py b/config/settings/production.py index d3602b234..237c9fd30 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -6,7 +6,7 @@ import environ -env = environ.Env() #Scope issues without this line? +env = environ.Env() # Scope issues without this line? BASE_URL = 'https://www.ubyssey.ca/' @@ -14,22 +14,30 @@ INTERNAL_IPS = ['127.0.0.1', '0.0.0.0', 'localhost'] -INSTALLED_APPS += [ -] +INSTALLED_APPS += [] # Sessions are used to anonymously keep track of individual site visitors SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' -# TODO: replace these cache backends with a persistent solution like Memcached or Redis. -# For now, use the default local memory cache. +# We use Redis as a cache backend, as recommended by Wagtail here: +# https://docs.wagtail.org/en/v2.10.2/advanced_topics/performance.html#cache +# +# We previously used the Memcache service bundled with Google App Engine, +# but it is now considered a legacy service and does not work seamlessly with Django. +# +# TODO: switch to built-in Redis backend after upgrading Django. +# Ref: https://github.com/ubyssey/ubyssey.ca/issues/1340 +# CACHES = { "default": { - "BACKEND": "django.core.cache.backends.locmem.LocMemCache", + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": "redis://%s:%s" % (REDIS_HOST, REDIS_PORT), }, # The "renditions" cache is for Wagtail image renditions. # Ref: https://docs.wagtail.org/en/v2.10.2/advanced_topics/performance.html#caching-image-renditions "renditions": { - "BACKEND": "django.core.cache.backends.locmem.LocMemCache", + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": "redis://%s:%s" % (REDIS_HOST, REDIS_PORT), } } diff --git a/requirements-prd.txt b/requirements-prd.txt index 8e4f11bc8..5548f0782 100644 --- a/requirements-prd.txt +++ b/requirements-prd.txt @@ -27,3 +27,6 @@ wagtailmenus==3.0.2 wagtail-cache==1.0.2 google-crc32c==1.3.0 wagtail-color-panel==1.4.0 +django-redis==5.4.0 +redis==5.0.1 +hiredis==2.2.3