ARTIFACTORY: How to Cache Only Certain Artifacts from a Remote Repository

Shai Ben-Zvi
2023-01-22 11:11

 

Currently, a given remote repository can either be configured to locally cache everything that is resolved from it or to cache nothing.
There are, however, two ways to cache only specific artifacts:

1. With a user plugin, using the beforeCreate entry point that will cancel the creation of a binary to the local cache if it doesn't match a defined pattern. 

2. Create two different remote repositories that both point to the same remote URL. One (let's call it Repo A) will have caching enabled and an exclude pattern that excludes those artifacts you don't want to cache locally; the other (Repo B) without an exclude/include pattern and without caching artifacts.

Repos A & B should be aggregated into one virtual repository where they are ordered as Repo A and Repo B.
Then, when a client tries to resolve from this virtual repository, Artifacory will first try to resolve from Repo A and, if a given artifact has not been excluded, it will be resolved and cached.
If a given artifact has been excluded from this repository, Artifactory will resolve it from Repo B and not cache it locally.

Published: May. 23, 2019
Last updated: May. 23, 2021

Keywords: remote repository, user plugins