Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redis cache #1339

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading