gitlab--缓存 cache (二)

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: gitlab--缓存 cache

创建 job 的缓存和缓存策略


上面我们使用的是全局的缓存,我们也可以给某个 job 设置缓存,也可以设置缓存的策略 push 或者 pull

stages:
  - build1
  - build2
  - build3
  - test1
  - test2
  - deploy
build1:
  stage: build1
  tags:
    - build
  before_script:
    - ls 
    - ls app
  cache:
    key: build1 # 为缓存提供唯一的标识键
    paths:
      - app/a.txt # 将 app 下的 a.txt 文件创建一个缓存
      - app/b.txt # 将 app 下的 b.txt 文件创建一个缓存
  script:
    - ls
    - id
    - echo 'test123' >> app/a.txt # 创建了个文件,模拟编译产生的文件
    - echo 'test456' >> app/b.txt # 创建了个文件,模拟编译产生的文件
    - ls app
build2:
  stage: build2
  tags:
    - build
  before_script:
    - ls 
    - ls app
  cache:
    key: build2 # 为缓存提供唯一的标识键
    paths:
      - app/c.txt # 将 app 下的 c.txt 文件创建一个缓存
  script:
    - ls
    - id
    - echo 'test123' >> app/c.txt # 创建了个文件,模拟编译产生的文件
    - ls app
build3:
  stage: build3
  tags:
    - build
  before_script:
    - ls 
    - ls app
  cache:
    # key: build3 # 没有设置 key,将使用 default
    paths:
      - app/e.txt # 将 app 下的 c.txt 文件创建一个缓存
  script:
    - ls
    - id
    - echo 'test666' >> app/e.txt # 创建了个文件,模拟编译产生的文件
    - ls app
test1:
  stage: test1
  tags:
    - build
  before_script:
    - ls 
    - ls app
  script:
    - echo "run test"
    - echo 'test' >> app/c.txt # 创建了个文件
    - ls app # 在查看 app 下的内容
  cache:
    policy: pull # 缓存的策略是仅在作业开始时下载缓存,但在作业完成时从不上传更改
    key: build1
    paths: # 使用了 key,必须要有 paths,下载 a.txt 文件
      - app/a.txt
      - app/c.txt # 缓存 build1 里没有 c.txt 文件,所以不会下载。由于策略原因,c.txt 文件也不会上传到缓存里
test2:
  stage: test2
  tags:
    - build
  before_script:
    - ls 
    - ls app
  script:
    - echo "run test"
    - echo 'test' >> app/d.txt
    - ls app # 在查看 app 下的内容
  cache:
    policy: push # 缓存的策略是仅在作业完成时上传缓存,但在作业开始时从不下载缓存
    key: build2
    paths:
      - app/d.txt # 由于策略设置的是 push,所以会上传
      - app/c.txt # 由于设置的策略是 push,所以不会下载 build2 里的 c.txt 文件,上传缓存时会给出警告
deploy:
  stage: deploy
  tags:
    - build
  before_script:
    - ls 
    - ls app
  script:
    - echo "run deploy"
    - ls app # 在查看 app 下的内容
  retry:
    max: 2
    when:
      - script_failure

运行上面的流水线,查看日志,先来查看 build1 的日志


build1 日志

可以看到,重置缓存的时候是去 build1-protected 下面去下载缓存的


build2 日志

可以看到,重置缓存的时候是去 build2-protected 下面去下载缓存的


build3 日志


进入 runner 里查看下缓存

test1 日志


test2 日志



deploy 日志


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
2月前
|
缓存 NoSQL Java
在 Spring Boot 应用中使用 Spring Cache 和 Redis 实现数据查询的缓存功能
在 Spring Boot 应用中使用 Spring Cache 和 Redis 实现数据查询的缓存功能
99 0
|
13天前
|
缓存 NoSQL Java
SpringBoot的三种缓存技术(Spring Cache、Layering Cache 框架、Alibaba JetCache 框架)
Spring Cache 是 Spring 提供的简易缓存方案,支持本地与 Redis 缓存。通过添加 `spring-boot-starter-data-redis` 和 `spring-boot-starter-cache` 依赖,并使用 `@EnableCaching` 开启缓存功能。JetCache 由阿里开源,功能更丰富,支持多级缓存和异步 API,通过引入 `jetcache-starter-redis` 依赖并配置 YAML 文件启用。Layering Cache 则提供分层缓存机制,需引入 `layering-cache-starter` 依赖并使用特定注解实现缓存逻辑。
SpringBoot的三种缓存技术(Spring Cache、Layering Cache 框架、Alibaba JetCache 框架)
|
26天前
|
存储 缓存 监控
Redis问题之如何使用Guava Cache来监控缓存的加载/命中情况
Redis问题之如何使用Guava Cache来监控缓存的加载/命中情况
|
26天前
|
存储 缓存 监控
Redis问题之使用Guava Cache相比自己设计本地缓存有哪些优势
Redis问题之使用Guava Cache相比自己设计本地缓存有哪些优势
|
2月前
|
存储 缓存
使用tp5内cache缓存,存储手机短信验证码
使用tp5内cache缓存,存储手机短信验证码
58 1
|
2月前
|
缓存 索引
cpu缓存一致性问题---cache写策略
cpu缓存一致性问题---cache写策略
19 1
|
3月前
|
存储 缓存 监控
中间件Read-Through Cache(直读缓存)策略实现方式
【5月更文挑战第11天】中间件Read-Through Cache(直读缓存)策略实现方式
47 4
中间件Read-Through Cache(直读缓存)策略实现方式
|
3月前
|
缓存 NoSQL Java
Spring Cache之本地缓存注解@Cacheable,@CachePut,@CacheEvict使用
SpringCache不支持灵活的缓存时间和集群,适合数据量小的单机服务或对一致性要求不高的场景。`@EnableCaching`启用缓存。`@Cacheable`用于缓存方法返回值,`value`指定缓存名称,`key`定义缓存键,可按SpEL编写,`unless`决定是否不缓存空值。当在类上使用时,类内所有方法都支持缓存。`@CachePut`每次执行方法后都会更新缓存,而`@CacheEvict`用于清除缓存,支持按键清除或全部清除。Spring Cache结合Redis可支持集群环境。
185 6
|
3月前
|
存储 缓存 中间件
中间件Read-Through Cache(直读缓存)策略工作原理
【5月更文挑战第11天】中间件Read-Through Cache(直读缓存)策略工作原理
34 3
|
3月前
|
存储 缓存 监控
中间件Read-Through Cache(直读缓存)策略注意事项
【5月更文挑战第11天】中间件Read-Through Cache(直读缓存)策略注意事项
26 2