From 3c64795f7a5881c323019ca616ebb0884c3bc944 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 5 Jan 2021 02:36:20 +0100 Subject: [PATCH] Add memcached config --- Dockerfile | 9 +++++++++ blog/settings.py | 8 ++++++++ poetry.lock | 17 ++++++++++++++++- pyproject.toml | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c9c3cf6..5bf9d6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,11 @@ ENV PYTHONPATH $PYTHONPATH:/root/.poetry/lib ARG POETRY_OPTIONS WORKDIR /app + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libmemcached-dev + COPY pyproject.toml poetry.lock ./ RUN python -m venv --copies /app/venv \ @@ -31,6 +36,10 @@ FROM python:3.8.6-slim-buster as prod RUN echo "Europe/Paris" > /etc/timezone \ && mkdir /db +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libmemcached-dev + COPY --from=venv /app/venv /app/venv/ ENV PATH /app/venv/bin:$PATH diff --git a/blog/settings.py b/blog/settings.py index 4b8cac6..8b2e90e 100644 --- a/blog/settings.py +++ b/blog/settings.py @@ -109,6 +109,14 @@ TEMPLATES = [ WSGI_APPLICATION = "blog.wsgi.application" +MEMCACHED_LOCATION = os.getenv("MEMCACHED_LOCATION") +if MEMCACHED_LOCATION: + CACHES = { + "default": { + "BACKEND": "django.core.cache.backends.memcached.PyLibMCCache", + "LOCATION": MEMCACHED_LOCATION, + } + } # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases diff --git a/poetry.lock b/poetry.lock index c35fa15..a7d5aa8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -378,6 +378,14 @@ category = "main" optional = false python-versions = ">=3.5" +[[package]] +name = "pylibmc" +version = "1.6.1" +description = "Quick and small memcached client for Python" +category = "main" +optional = false +python-versions = "*" + [[package]] name = "pyparsing" version = "2.4.7" @@ -625,7 +633,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "e55cff591236bac6ee7f57a2da6cb48fcf0484f5a1d17a26949c3c724dad0087" +content-hash = "95c3ac9ea5b53ca0646c04fe708143d8affe331c1a0b71204b59315f00347d4f" [metadata.files] appdirs = [ @@ -921,6 +929,13 @@ pygments = [ {file = "Pygments-2.7.3-py3-none-any.whl", hash = "sha256:f275b6c0909e5dafd2d6269a656aa90fa58ebf4a74f8fcf9053195d226b24a08"}, {file = "Pygments-2.7.3.tar.gz", hash = "sha256:ccf3acacf3782cbed4a989426012f1c535c9a90d3a7fc3f16d231b9372d2b716"}, ] +pylibmc = [ + {file = "pylibmc-1.6.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:01a7e2e3fa9fcd7a791c7818a80a07e7a381aee988a5d810a1c1e6f7a9a288fd"}, + {file = "pylibmc-1.6.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:6fff384e3c30af029bbac87f88b3fab14ae87b50103d389341d9b3e633349a3f"}, + {file = "pylibmc-1.6.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:c749b4251c1137837d00542b62992b96cd2aed639877407f66291120dd6de2ff"}, + {file = "pylibmc-1.6.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e6c0c452336db0868d0de521d48872c2a359b1233b974c6b32c36ce68abc4820"}, + {file = "pylibmc-1.6.1.tar.gz", hash = "sha256:8a8dd406487d419d58c6d944efd91e8189b360a0c4d9e8c6ebe3990d646ae7e9"}, +] pyparsing = [ {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, diff --git a/pyproject.toml b/pyproject.toml index 9955af1..b89c878 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ html2text = "^2020.1.16" readtime = "^1.1.1" django-compressor = "^2.4" "calmjs.parse" = "^1.2.5" +pylibmc = "^1.6.1" [tool.poetry.dev-dependencies] pre-commit = "^2.7"