From 5d00c6102370b55417cd463022b873d6c8195edf Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Tue, 3 Sep 2019 14:21:48 +0200
Subject: [PATCH] Enable caching and memcached support. Advances #76.

---
 biscuit/core/settings.py | 9 +++++++++
 pyproject.toml           | 1 +
 2 files changed, 10 insertions(+)

diff --git a/biscuit/core/settings.py b/biscuit/core/settings.py
index 7f399bca6..e85c60271 100644
--- a/biscuit/core/settings.py
+++ b/biscuit/core/settings.py
@@ -83,6 +83,7 @@ SASS_PROCESSOR_INCLUDE_DIRS = [
 ]
 
 MIDDLEWARE = [
+    'django.middleware.cache.UpdateCacheMiddleware',
     'debug_toolbar.middleware.DebugToolbarMiddleware',
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
@@ -96,6 +97,7 @@ MIDDLEWARE = [
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'easyaudit.middleware.easyaudit.EasyAuditMiddleware',
     'maintenance_mode.middleware.MaintenanceModeMiddleware',
+    'django.middleware.cache.FetchFromCacheMiddleware'
 ]
 
 ROOT_URLCONF = 'biscuit.core.urls'
@@ -138,6 +140,13 @@ DATABASES = {
     }
 }
 
+if _settings.get('caching.memcached.enabled', True):
+    CACHES = {
+        'default': {
+            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+            'LOCATION': _settings.get('caching.memcached.address', '127.0.0.1:11211')
+        }
+    }
 
 # Password validation
 # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
diff --git a/pyproject.toml b/pyproject.toml
index 738baa503..f2f0414d9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -44,6 +44,7 @@ easy-thumbnails = "^2.6"
 django-image-cropping = "^1.2"
 django-contact-form = "^1.7"
 django-impersonate = "^1.4"
+python-memcached = "^1.59"
 
 [tool.poetry.extras]
 ldap = ["django-auth-ldap"]
-- 
GitLab