|
| 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. |
0 commit comments