From c4789fb9a440252980751ef26aa45be339fd3fc2 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 23 Jun 2015 19:57:34 +0200 Subject: [PATCH] Fixed #73 -- Add memcached configuration options --- deployment/docker/standalone/Dockerfile | 3 ++- doc/admin/config.rst | 15 ++++++++++++++- src/pretix/settings.py | 8 ++++++++ src/requirements/memcached.txt | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/requirements/memcached.txt diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index fa975afc01..6b2995d3c4 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -3,7 +3,7 @@ FROM debian:jessie RUN apt-get update && apt-get install -y supervisor python3 git python3-pip \ libxml2-dev libxslt1-dev python-dev python-virtualenv locales libffi-dev \ build-essential python3-dev zlib1g-dev libssl-dev npm gettext git \ - libpq-dev libmysqlclient-dev \ + libpq-dev libmysqlclient-dev libmemcached-dev \ --no-install-recommends WORKDIR / @@ -27,6 +27,7 @@ WORKDIR /pretix/src RUN pip3 install -r requirements.txt RUN pip3 install -r requirements/mysql.txt RUN pip3 install -r requirements/postgres.txt +RUN pip3 install -r requirements/memcached.txt RUN pip3 install gunicorn RUN make diff --git a/doc/admin/config.rst b/doc/admin/config.rst index 05d1061815..12661ff290 100644 --- a/doc/admin/config.rst +++ b/doc/admin/config.rst @@ -93,7 +93,7 @@ Example:: Connection details for the database connection. Empty by default. URLs ------ +---- Example:: @@ -161,4 +161,17 @@ Example:: .. WARNING:: Never set this to ``True`` in production! +Memcached +--------- + +You can use an existing memcached server as pretix's caching backend:: + + [memcached] + location=127.0.0.1:11211 + +``location`` + The location of memcached, either a host:port combination or a socket file. + +If no memcached is configures, pretix will use Django's built-in local-memory caching method. + .. _Python documentation: https://docs.python.org/3/library/configparser.html?highlight=configparser#supported-ini-file-structure \ No newline at end of file diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 5cf3ae5d69..a59994b257 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -74,6 +74,14 @@ SESSION_COOKIE_SECURE = SESSION_COOKIE_HTTPONLY = config.getboolean( LANGUAGE_COOKIE_DOMAIN = SESSION_COOKIE_DOMAIN = CSRF_COOKIE_DOMAIN = config.get( 'pretix', 'cookiedomain', fallback=None) +if config.has_option('memcached', 'location'): + CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', + 'LOCATION': config.get('memcached', 'location'), + } + } + # Internal settings STATIC_ROOT = '_static' diff --git a/src/requirements/memcached.txt b/src/requirements/memcached.txt new file mode 100644 index 0000000000..a19a29cf28 --- /dev/null +++ b/src/requirements/memcached.txt @@ -0,0 +1 @@ +pylibmc