From a9ea0b4533d3b135fb4f536883687a87610c3cf1 Mon Sep 17 00:00:00 2001 From: Peter Thomassen Date: Wed, 2 Sep 2026 00:35:32 +0200 Subject: [PATCH] chore(api): use pymemcache instead of pylibmc pymemcache is a pure-Python memcached client, so the API image no longer needs to compile a C extension against libmemcached. Django closes cache connections at the end of each request, so the new backend reconnects to memcached per request. TCP_NODELAY avoids Nagle delays when storing the serial list and throttle histories. --- README.md | 2 +- api/Dockerfile | 2 +- api/api/settings.py | 7 +++++-- api/requirements.txt | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c55bcbdec..bb58e1fd2 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ While there are certainly many ways to get started hacking desec-stack, here is jq, httpie, libmariadbclient-dev, libpq-dev, python3-dev (>= 3.12) and python3-venv (>= 3.12) are useful if you want to follow this guide. The webapp requires Node.js. To install everything you need for this guide except docker and docker compose, use - sudo apt install certbot curl git httpie jq libmariadbclient-dev libpq-dev nodejs npm python3-dev python3-venv libmemcached-dev + sudo apt install certbot curl git httpie jq libmariadbclient-dev libpq-dev nodejs npm python3-dev python3-venv 1. **Get the code.** Clone this repository to your favorite location. diff --git a/api/Dockerfile b/api/Dockerfile index 980692be7..da3802dd3 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -13,7 +13,7 @@ ENV PIP_NO_CACHE_DIR=1 COPY requirements.txt /usr/src/app/ # freetype-dev is needed for captcha generation -RUN apk add --no-cache gcc freetype-dev libffi-dev musl-dev libmemcached-dev postgresql-dev jpeg-dev zlib-dev +RUN apk add --no-cache gcc freetype-dev libffi-dev musl-dev postgresql-dev jpeg-dev zlib-dev RUN pip install --upgrade pip \ && pip install -r requirements.txt \ && pip freeze diff --git a/api/api/settings.py b/api/api/settings.py index ef0988979..123caa875 100644 --- a/api/api/settings.py +++ b/api/api/settings.py @@ -68,9 +68,12 @@ CACHES = { "default": { - # TODO 'BACKEND': 'django_prometheus.cache.backends.memcached.PyLibMCCache' not supported - "BACKEND": "django.core.cache.backends.memcached.PyLibMCCache", + # Django closes cache connections at the end of each request, so this backend + # reconnects to memcached per request. Subclassing it with a no-op close() + # keeps the connection open, should the reconnects ever become noticeable. + "BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache", "LOCATION": "memcached:11211", + "OPTIONS": {"no_delay": True}, } } diff --git a/api/requirements.txt b/api/requirements.txt index 605aac4f4..5fb150450 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -13,7 +13,7 @@ dnspython~=2.8.0 pyotp~=2.9.0 psycopg[binary]~=3.3.4 psl-dns~=1.1.1 -pylibmc~=1.6.3 +pymemcache~=4.0.0 pyyaml~=6.0.3 requests~=2.32.5 responses~=0.26.2