Skip to content

Commit

Permalink
Merge pull request #1339 from ubyssey/perf-redis-cache
Browse files Browse the repository at this point in the history
Add Redis cache from @psiemens
  • Loading branch information
SamuelmdLow authored Oct 31, 2023
2 parents b785b02 + c2247a2 commit 32f4fb3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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')}
Expand Down
22 changes: 15 additions & 7 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,38 @@

import environ

env = environ.Env() #Scope issues without this line?
env = environ.Env() # Scope issues without this line?

BASE_URL = 'https://www.ubyssey.ca/'

ALLOWED_HOSTS = ['localhost', '*']

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),
}
}

Expand Down
3 changes: 3 additions & 0 deletions requirements-prd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 32f4fb3

Please sign in to comment.