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

Enable Django cache in production #1334

Merged
merged 3 commits into from
Oct 26, 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
14 changes: 9 additions & 5 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,22 @@
'django.contrib.messages.context_processors.messages',
'wagtail.contrib.settings.context_processors.settings',
'wagtailmenus.context_processors.wagtailmenus',
'config.context_processors.get_light_mode',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'dbtemplates.loader.Loader',
(
'django.template.loaders.cached.Loader',
[
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'dbtemplates.loader.Loader',
],
),
],
},
}
]

TEMPLATES[0]['OPTIONS']['context_processors'].append("config.context_processors.get_light_mode")

# REST framework settings
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
Expand Down
5 changes: 2 additions & 3 deletions config/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

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

# Easily manipulable file cache for proof of concept for front page etc.
# The dummy cache does not cache any values. We use this in development
# so that the website always updates after code changes.
CACHES = {
"default": {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
# "BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
# "LOCATION": "/workspaces/ubyssey.ca/cache/",
}
}

Expand Down
10 changes: 4 additions & 6 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
# Sessions are used to anonymously keep track of individual site visitors
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'

# Caches are used to store the results of SQL queries so it can be quickly retrieved and needs to do less work
# The cache requires a Memcached instance be set up in Google Cloud Platform (GCP) and access connectors to be set both on GCP and in app.yaml
# TODO: replace this cache backend with a distributed solution like Memcached or Redis.
# For now, use the default local memory cache.
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
# 'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
# 'LOCATION': '10.18.240.4:11211',
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
}
}

Expand Down
Loading