Skip to content

Commit

Permalink
utils: Allow to define cache directory separately
Browse files Browse the repository at this point in the history
This setting was already used in Docker, now it is extended to
general.

See #2984
  • Loading branch information
nijel committed Jan 19, 2023
1 parent 6f9161b commit 2bf3f0a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
22 changes: 21 additions & 1 deletion docs/admin/config.rst
Expand Up @@ -267,6 +267,21 @@ You can pass additional arguments to :command:`borg create` when built-in backup
:ref:`backup`,
:doc:`borg:usage/create`

.. setting:: CACHE_DIR

CACHE_DIR
---------

.. versionadded:: 4.16

Directory where Weblate stores cache files. Defaults to :file:`cache` subfolder
in :setting:`DATA_DIR`.

Change this to local or temporary filesystem if :setting:`DATA_DIR` is on a
network filesystem.

The Docker container uses a separate volume for this, see :ref:`docker-volume`.

.. setting:: CSP_SCRIPT_SRC
.. setting:: CSP_IMG_SRC
.. setting:: CSP_CONNECT_SRC
Expand Down Expand Up @@ -409,6 +424,10 @@ The following subdirectories usually exist:
Celery scheduler data, see :ref:`celery`.
:file:`fonts`:
User-uploaded fonts, see :ref:`fonts`.
:file:`cache`
Various caches, can be placed elsewhere using :setting:`CACHE_DIR`.

The Docker container uses a separate volume for this, see :ref:`docker-volume`.

.. note::

Expand All @@ -426,7 +445,8 @@ Defaults to ``/home/weblate/data``, but it is expected to be configured.
.. seealso::

:ref:`file-permissions`,
:doc:`backup`
:doc:`backup`,
:setting:`CACHE_DIR`

.. setting:: DATABASE_BACKUP

Expand Down
4 changes: 2 additions & 2 deletions docs/admin/install/docker.rst
Expand Up @@ -1601,8 +1601,8 @@ consist of name of your docker-compose directory, container, and volume names).
In the container it is mounted as :file:`/app/data`.

The cache volume is mounted as :file:`/app/cache` and is used to store static
files. Its content is recreated on container startup and the volume can be
mounted using ephemeral filesystem such as `tmpfs`.
files and :setting:`CACHE_DIR`. Its content is recreated on container startup
and the volume can be mounted using ephemeral filesystem such as `tmpfs`.

When creating the volumes manually, the directories should be owned by UID 1000
as that is user used inside the container.
Expand Down
1 change: 1 addition & 0 deletions weblate/settings_example.py
Expand Up @@ -66,6 +66,7 @@
# Data directory, you can use following for the development purposes:
# os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data")
DATA_DIR = "/home/weblate/data"
CACHE_DIR = f"{DATA_DIR}/cache"

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand Down
1 change: 1 addition & 0 deletions weblate/settings_test.py
Expand Up @@ -54,6 +54,7 @@
else:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATA_DIR = os.path.join(BASE_DIR, "data-test")
CACHE_DIR = os.path.join(DATA_DIR, "cache")
MEDIA_ROOT = os.path.join(DATA_DIR, "media")
STATIC_ROOT = os.path.join(DATA_DIR, "static")
CELERY_BEAT_SCHEDULE_FILENAME = os.path.join(DATA_DIR, "celery", "beat-schedule")
Expand Down
3 changes: 3 additions & 0 deletions weblate/trans/models/_conf.py
Expand Up @@ -9,6 +9,9 @@ class WeblateConf(AppConf):
# Data directory
DATA_DIR = None

# Cache directory
CACHE_DIR = None

# Akismet API key
AKISMET_API_KEY = None

Expand Down
2 changes: 2 additions & 0 deletions weblate/utils/data.py
Expand Up @@ -10,4 +10,6 @@

def data_dir(component, *args):
"""Return path to data dir for given component."""
if component == "cache" and settings.CACHE_DIR:
return os.path.join(settings.CACHE_DIR, *args)
return os.path.join(settings.DATA_DIR, component, *args)

0 comments on commit 2bf3f0a

Please sign in to comment.