From 3d733ed6af9b208ce14451f9516dc632ad720a54 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 21 Sep 2020 15:13:43 +0200 Subject: [PATCH] Use memcached cache --- .gitlab-ci.yml | 4 ++-- Dockerfile | 2 +- README.md | 4 ++-- ansible/roles/1-apt-basic/tasks/main.yml | 4 ++++ note_kfet/settings/base.py | 10 ++++++++++ note_kfet/settings/development.py | 8 ++++++++ requirements.txt | 1 + 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 61d5988c..2181b4b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,7 +17,7 @@ py37-django22: python3-django python3-django-crispy-forms python3-django-extensions python3-django-filters python3-django-polymorphic python3-djangorestframework python3-django-oauth-toolkit python3-psycopg2 python3-pil - python3-babel python3-lockfile python3-pip python3-phonenumbers + python3-babel python3-lockfile python3-pip python3-phonenumbers python3-memcache python3-bs4 python3-setuptools tox texlive-xetex script: tox -e py37-django22 @@ -34,7 +34,7 @@ py38-django22: python3-django python3-django-crispy-forms python3-django-extensions python3-django-filters python3-django-polymorphic python3-djangorestframework python3-django-oauth-toolkit python3-psycopg2 python3-pil - python3-babel python3-lockfile python3-pip python3-phonenumbers + python3-babel python3-lockfile python3-pip python3-phonenumbers python3-memcache python3-bs4 python3-setuptools tox texlive-xetex script: tox -e py38-django22 diff --git a/Dockerfile b/Dockerfile index 9696de7c..95a62437 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update && \ python3-django python3-django-crispy-forms \ python3-django-extensions python3-django-filters python3-django-polymorphic \ python3-djangorestframework python3-django-oauth-toolkit python3-psycopg2 python3-pil \ - python3-babel python3-lockfile python3-pip python3-phonenumbers ipython3 \ + python3-babel python3-lockfile python3-pip python3-phonenumbers python3-memcache ipython3 \ python3-bs4 python3-setuptools \ uwsgi uwsgi-plugin-python3 \ texlive-xetex gettext libjs-bootstrap4 fonts-font-awesome && \ diff --git a/README.md b/README.md index 910fd19a..77166649 100644 --- a/README.md +++ b/README.md @@ -94,9 +94,9 @@ Sinon vous pouvez suivre les étapes décrites ci-dessous. python3-django python3-django-crispy-forms \ python3-django-extensions python3-django-filters python3-django-polymorphic \ python3-djangorestframework python3-django-oauth-toolkit python3-psycopg2 python3-pil \ - python3-babel python3-lockfile python3-pip python3-phonenumbers ipython3 \ + python3-babel python3-lockfile python3-pip python3-phonenumbers python3-memcache ipython3 \ python3-bs4 python3-setuptools \ - uwsgi uwsgi-plugin-python3 \ + memcached uwsgi uwsgi-plugin-python3 \ texlive-xetex gettext libjs-bootstrap4 fonts-font-awesome \ nginx python3-venv git acl ``` diff --git a/ansible/roles/1-apt-basic/tasks/main.yml b/ansible/roles/1-apt-basic/tasks/main.yml index 95f6d40a..9c01dd97 100644 --- a/ansible/roles/1-apt-basic/tasks/main.yml +++ b/ansible/roles/1-apt-basic/tasks/main.yml @@ -30,6 +30,7 @@ - python3-django-polymorphic - python3-djangorestframework - python3-lockfile + - python3-memcache - python3-phonenumbers - python3-pil - python3-pip @@ -40,6 +41,9 @@ # LaTeX (PDF generation) - texlive-xetex + # Cache server + - memcached + # WSGI server - uwsgi - uwsgi-plugin-python3 diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index ac9dd050..f319b2db 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -216,6 +216,16 @@ EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD', None) SERVER_EMAIL = os.getenv("NOTE_MAIL", "notekfet@example.com") DEFAULT_FROM_EMAIL = "NoteKfet2020 <" + SERVER_EMAIL + ">" +# Cache +# https://docs.djangoproject.com/en/2.2/topics/cache/#setting-up-the-cache +cache_address = os.getenv("CACHE_ADDRESS", "127.0.0.1:11211") +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': cache_address, + } +} + # Django REST Framework REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ diff --git a/note_kfet/settings/development.py b/note_kfet/settings/development.py index 282ee478..e4fc8826 100644 --- a/note_kfet/settings/development.py +++ b/note_kfet/settings/development.py @@ -24,6 +24,14 @@ if os.getenv("DJANGO_DEV_STORE_METHOD", "sqlite") != "postgresql": } } +# Dummy cache for development +# https://docs.djangoproject.com/en/2.2/topics/cache/#setting-up-the-cache +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } +} + # Break it, fix it! DEBUG = True diff --git a/requirements.txt b/requirements.txt index 33ba454a..bf0917cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,5 +13,6 @@ django-polymorphic~=2.0.3 djangorestframework~=3.9.0 django-rest-polymorphic~=0.1.9 django-tables2~=2.3.1 +python-memcache~=1.59 phonenumbers~=8.9.10 Pillow>=5.4.1