Skip to content

Commit 28695ca

Browse files
committed
Add Redis cache configuration
1 parent fac6784 commit 28695ca

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

config/settings/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@
8484
USE_TZ=(bool,True),
8585
TIME_ZONE=(str,'Canada/Pacific'),
8686

87-
# Database defaults:
87+
# SQL defaults
8888
SQL_HOST = (str, 'db'),
89-
SQL_DATABASE= (str, 'ubyssey'),
89+
SQL_DATABASE = (str, 'ubyssey'),
9090
SQL_USER = (str, 'root'),
9191
SQL_PASSWORD = (str, 'ubyssey'),
9292

93+
# Redis defaults
94+
REDIS_HOST = (str, '127.0.0.1'),
95+
REDIS_PORT = (str, '6379'),
96+
9397
# Keys
9498
SECRET_KEY = (str, 'thisisakey'),
9599
NOTIFICATION_KEY= (str, 'thisisakeytoo'),
@@ -115,6 +119,9 @@
115119
ADS_TXT_URL = env('ADS_TXT_URL')
116120
ROOT_URLCONF = env('ROOT_URLCONF')
117121

122+
REDIS_HOST = env('REDIS_HOST')
123+
REDIS_PORT = env('REDIS_PORT')
124+
118125
# Initialize the databases.
119126
# Note it should be possible to parse all this information in a single line:
120127
# DATABASES = {'default': env.db('DATABASE_URL')}

config/settings/production.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,29 @@
66

77
import environ
88

9-
env = environ.Env() #Scope issues without this line?
9+
env = environ.Env() # Scope issues without this line?
1010

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

1313
ALLOWED_HOSTS = ['localhost', '*']
1414

1515
INTERNAL_IPS = ['127.0.0.1', '0.0.0.0', 'localhost']
1616

17-
INSTALLED_APPS += [
18-
]
17+
INSTALLED_APPS += []
1918

2019
# Sessions are used to anonymously keep track of individual site visitors
2120
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
2221

23-
# TODO: replace these cache backends with a persistent solution like Memcached or Redis.
24-
# For now, use the default local memory cache.
2522
CACHES = {
2623
"default": {
27-
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
24+
"BACKEND": "django_redis.cache.RedisCache",
25+
"LOCATION": "redis://%s:%s" % (REDIS_HOST, REDIS_PORT),
2826
},
2927
# The "renditions" cache is for Wagtail image renditions.
3028
# Ref: https://docs.wagtail.org/en/v2.10.2/advanced_topics/performance.html#caching-image-renditions
3129
"renditions": {
32-
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
30+
"BACKEND": "django_redis.cache.RedisCache",
31+
"LOCATION": "redis://%s:%s" % (REDIS_HOST, REDIS_PORT),
3332
}
3433
}
3534

requirements-prd.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ wagtailmenus==3.0.2
2727
wagtail-cache==1.0.2
2828
google-crc32c==1.3.0
2929
wagtail-color-panel==1.4.0
30+
django-redis==5.4.0
31+
redis==5.0.1
32+
hiredis==2.2.3

0 commit comments

Comments
 (0)