You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Artifactory缓存清理优先级以优先保留大文件

Artifactory缓存清理:优先保留大文件的配置方案

问题背景

我们希望配置Artifactory的缓存清理设置,优先保留大文件,即便其访问频率低于小文件。核心顾虑是大文件被清理后重新获取会产生显著的下载速度损耗,远高于小文件。需要明确:

  • 是否存在原生配置或官方推荐方案,可调整缓存清理优先级并将文件大小纳入考量?
  • 若没有原生支持,有哪些可行的变通方法或脚本实现该行为?

当前使用的binarystore.xml配置如下:

$ cat ./app/misc/etc/artifactory/binarystore.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Artifactory is a binaries repository manager.
  ~ Copyright (C) 2019 JFrog Ltd.
  ~
  ~ Artifactory is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU Affero General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ Artifactory is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY;
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU Affero General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Affero General Public License
  ~ along with Artifactory.  If not, see <http://www.gnu.org/licenses/>.
  -->
<!--
    This file configures Artifactory's binary provider
-->

<!--
  ~ TAKE CARE! Making changes to this file may result in losing binaries stored in Artifactory!
  ~ If you are not sure of what you are doing, please contact JFrog Support for assistance.
  -->

<config version="1">
    <chain template="file-system"/>
</config>

解决方案

一、原生配置间接实现(Artifactory 7.x及以上版本)

Artifactory默认缓存清理基于LRU(最近最少使用)规则,原生不支持直接将文件大小作为优先级权重,但可以通过属性标记+清理规则排除的方式间接实现优先保留大文件:

  1. 标记大文件:通过UI或REST API,给超过指定阈值(如1GB)的文件添加自定义属性,例如keep_priority=high。
  2. 配置清理规则:在目标仓库的缓存设置中,添加排除规则,过滤带有keep_priority=high属性的文件;剩余文件仍按LRU或其他默认规则清理。
    • 操作路径:仓库配置 → 缓存 → 清理规则 → 添加排除条件,选择属性匹配keep_priority=high。

二、自定义脚本实现精准控制

如果原生配置无法满足需求,可通过Artifactory REST API编写脚本实现自定义清理逻辑:

  1. 核心逻辑步骤:
    • 调用API拉取目标仓库所有缓存文件的元数据(包含大小、最后访问时间、路径)。
    • 按文件大小降序排序,保留占缓存总容量指定比例(如70%)的大文件,或直接保留前N个大文件。
    • 对剩余文件按LRU规则筛选出需清理的对象,调用API执行删除。
  2. 关键API示例:
    • 获取仓库文件列表:GET /api/storage/{repoKey}?list&deep=1&listFolders=0
    • 获取单个文件元数据:GET /api/storage/{repoKey}/{filePath}
    • 删除文件:DELETE /api/storage/{repoKey}/{filePath}
  3. 注意事项:
    • 分页拉取文件数据,避免单次请求过大导致性能问题。
    • 加入日志记录,便于追踪清理操作。
    • 先在测试环境验证脚本逻辑,再部署到生产环境。

三、关于binarystore.xml的说明

当前的binarystore.xml仅配置了文件系统存储链,和缓存清理策略无关。缓存清理规则是在仓库级配置中设置,无需修改此文件。


内容的提问来源于stack exchange,提问作者Rabin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:36:07