From 4b5bed71f63f7282235b3831b8991af811524056 Mon Sep 17 00:00:00 2001 From: Peter Siemens Date: Wed, 25 Oct 2023 09:02:25 -0700 Subject: [PATCH 1/3] Use LocMemCache in production --- config/settings/production.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/config/settings/production.py b/config/settings/production.py index 9dfb64c8c..0c094de54 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -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", } } From 59f23bd631398fd538c4944262409c1cd1fd20a5 Mon Sep 17 00:00:00 2001 From: Peter Siemens Date: Wed, 25 Oct 2023 09:03:05 -0700 Subject: [PATCH 2/3] Clean up development cache setting --- config/settings/development.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config/settings/development.py b/config/settings/development.py index 9d3d65505..8d5e185fe 100644 --- a/config/settings/development.py +++ b/config/settings/development.py @@ -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/", } } From 4a13b1ea5453ddfae7578b645f2c8b2944de365d Mon Sep 17 00:00:00 2001 From: Peter Siemens Date: Wed, 25 Oct 2023 09:03:25 -0700 Subject: [PATCH 3/3] Use cached template loader for custom template loaders --- config/settings/base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index c428ea1f7..69021e824 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -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': (