Skip to content

Commit c902069

Browse files
memshardeddanimtbjgsogo
authored
configuration section and download cache docs (conan-io#1544)
* configuration section and download cache docs * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Daniel <[email protected]> * review * Update configuration/download_cache.rst Co-Authored-By: Javier G. Sogo <[email protected]> * Update configuration/download_cache.rst Co-Authored-By: Javier G. Sogo <[email protected]> * review 2 Co-authored-by: Daniel <[email protected]> Co-authored-by: Javier G. Sogo <[email protected]>
1 parent 3d903c4 commit c902069

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

configuration.rst

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _configuration:
2+
3+
Configuration
4+
---------------
5+
6+
The Conan client can be configured to behave differently. Most of the configuration can be found in the :ref:`conan.conf reference <conan_conf>`,
7+
but this section aims to be an introduction to the configuration based on different use cases.
8+
9+
.. toctree::
10+
:maxdepth: 1
11+
12+
configuration/download_cache

configuration/download_cache.rst

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.. _download_cache:
2+
3+
Download cache
4+
==============
5+
6+
.. warning::
7+
8+
This is an **experimental** feature subject to breaking changes in future releases.
9+
10+
.. warning::
11+
12+
This is an **advanced** feature, use it only if you fully understand this document. Do not use it if you are mixing api V1 (without revisions)
13+
and api V2 (with revisions) clients.
14+
15+
16+
17+
Conan implements a shared download cache that can be used to reduce the time needed to populate the Conan package cache
18+
with commands like :command:`install`, :command:`create`.
19+
20+
This cache is purely an optimization mechanism. It is completely different to the :ref:`Conan package cache <custom_cache>`, (typically the ``<userhome>/.conan`` folder).
21+
It is not related to the ``short_paths`` mechanism for long path in Windows, nor to the ``short_paths`` cache folder. The cache will contain a copy
22+
of the artifacts, it is not a new location of files. Those files will still be copied to the Conan package cache, which will not change anything,
23+
its behavior, layout or location of any file.
24+
25+
This cache (whose path can be configured in the *conan.conf* file) will store the following items:
26+
27+
- All files that are downloaded from a Conan server (conan_server, Artifactory), both in the api V1 (without revisions) and V2 (with revisions).
28+
This includes files like *conanfile.py*, but also the zipped artifacts like *conan_package.tgz* or *conan_sources.tgz*.
29+
- The downloads done by users with the ``tools.download()`` or ``tools.get()`` helpers, as long as they provide a checksum (md5, sha1, etc.). If
30+
a checksum is not provided, even if the download cache is enabled, the download will be always executed and the files will not be cached.
31+
32+
The cache computes a sha256 checksum of the download URL and the file checksum whenever is available.
33+
34+
.. warning::
35+
36+
As not always the file checksums are available, the download cache will not be able to correctly cache artifacts with revisions enabled
37+
if those artifacts are created and uploaded repeatedly in a client without revisions, because that will keep overwriting the revision "0".
38+
Similarly, the download cache will fail if a proxy suddenly and transparently changes a existing server and moves it to a new location,
39+
without the clients changing the URL too.
40+
41+
42+
Activating/deactivating the download cache
43+
------------------------------------------
44+
45+
The download cache is activated and configured in the :ref:`conan_conf` like this:
46+
47+
.. code-block:: text
48+
49+
[storage]
50+
download_cache=/path/to/my/cache
51+
52+
It can be defined from the command line:
53+
54+
.. code-block:: bash
55+
56+
$ conan config set storage.download_cache="/path/to/my/cache"
57+
# Display it
58+
$ conan config get storage.download_cache
59+
60+
61+
And, as the *conan.conf* is part of the configuration, you can also put a common *conan.conf* file in a git repo or zip file and use
62+
the :ref:`conan_config_install` command to automatically install it in Conan clients.
63+
64+
65+
To deactivate the download cache, you can remove the entry ``download_cache`` from the *conan.conf* with the command:
66+
67+
.. code-block:: bash
68+
69+
$ conan config rm storage.download_cache
70+
71+
72+
Concurrency, multiple caches and CI
73+
-----------------------------------
74+
75+
The downloads cache implements exclusive locks for concurrency, so it can be shared among different concurrent Conan instances.
76+
This is a typical scenario in CI servers, in which each job uses a different Conan package cache (defined by ``CONAN_USER_HOME`` environment
77+
variable). Every different Conan instance could configure its download cache to share the same storage. The download cache implements interprocess
78+
exclusive locks, so only 1 process will access at a time to a given cached artifact. If other processes needs the same artifact, they will wait
79+
until it is released, avoiding multiple downloads of the same file, even if they were requested almost simultaneously.
80+
81+
For Continuous Integration processes, it is recommended to have a different Conan package cache (``CONAN_USER_HOME``) for each job, in most of the cases,
82+
because the Conan package cache is not concurrent, and it might also have old dependencies, stale packages, etc. It is better to run CI jobs in a clean
83+
environment.
84+
85+
86+
Removing cached files
87+
---------------------
88+
89+
The download cache will store a lot of artifacts, for all recipes, packages, versions and configurations that are used. This can grow and consume
90+
a lot of storage. If you are using this feature, provide for a sufficiently large and fast download cache folder.
91+
92+
At the moment, it is only a folder. You can clean the cached artifacts just by removing that folder and its contents. You might also be able to
93+
run scripts and jobs that remove old artifacts only. If you do such operations, please make sure that there are not other Conan processes using
94+
it simultaneously, or they might fail.

index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Contents:
2424
systems_cross_building
2525
extending
2626
integrations
27+
configuration
2728
howtos
2829
reference
2930
videos

reference/config_files/conan.conf.rst

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The typical location of the **conan.conf** file is the directory ``~/.conan/``:
6666
# path beginning with "~" (if the environment var CONAN_USER_HOME is specified, this directory, even
6767
# with "~/", will be relative to the conan user home, not to the system user home)
6868
path = ./data
69+
# download_cache = /path/to/my/cache
6970
7071
[proxies]
7172
# Empty (or missing) section will try to use system proxies.
@@ -218,6 +219,13 @@ On Windows:
218219
If you want to change the default "conan home" (directory where ``conan.conf`` file is) you can adjust
219220
the environment variable ``CONAN_USER_HOME``.
220221

222+
223+
The ``storage.download_cache`` variable defines the path to a folder that can be used to cache the different file downloads from Conan servers but
224+
also from user downloads via the ``tools.get()`` and ``tools.download()`` methods that provide a checksum. Defining this variable will both configure
225+
the path and activate the download cache. If it is not defined, the download cache will not be used.
226+
227+
Read more about the :ref:`download cache here <download_cache>`.
228+
221229
.. _proxys:
222230

223231
Proxies

0 commit comments

Comments
 (0)