How to cache only certain artifacts from a remote repository?

Shai Ben-Zvi
2019-05-23 10:18

Subject 

How to cache only certain artifacts from a remote repository?

Description

Currently, remote repositories can either be configured to locally cache everything that is resolved from the remote repository or to not cache anything.
This article will provide two solutions two achieve caching of only specific artifacts.

Resolution

There are two ways to achieving it:
1) With a
user plugin, by using the beforeCreate entry point to cancel the creation of a binary to the local cache if it does not match a predefined pattern.

2) Create two different remote repositories pointing to the same remote URL, one (let’s call it repoA) with caching enabled and an exclude pattern to exclude the artifacts you do not want to cache locally, the other (repoB) without an exclude/include pattern and without caching artifacts.

Both remote repositories should be aggregated in one virtual repository where the order of the repositories is repoA before repoB, so when a client tries to resolve from this virtual repository, Artifactory will first try to resolve from repoA, if the artifact is not excluded it will be resolved and cached; If the file is excluded from this repository, Artifactory will resolve it from repoB and not cache it locally.