Skip to content

缓存

¥Caching

一些内置插件实现了智能缓存机制,通过减少需要完成的工作量,大幅加快了连续构建的速度。本指南讲解了如何在不同环境中配置缓存。

¥Some of the built-in plugins implement intelligent caching mechanisms, which massively speed up consecutive builds by reducing the amount of work that needs to be done. This guide explains how to configure caching in different environments.

先决条件

¥Prerequisites

缓存完全是可选的,但默认启用。您可以根据插件禁用它。如果没有配置,插件会将其数据缓存在项目根目录下的.cache文件夹中。因此,建议在项目根目录中创建一个.gitignore文件:

¥Caching is entirely optional but enabled by default. It can be disabled per plugin. If not configured otherwise, plugins will cache their data in the .cache folder in the root of your project. For this reason it's recommended to create a .gitignore file in the root of your project:

.gitignore
.cache

这可以确保缓存文件不会被添加到你的 git 仓库中——除非绝对必要,否则通常不建议这样做。在某些情况下,你可能需要签入缓存文件,例如,当你需要在本地预生成社交卡片时,或者当你无法在持续集成 (CI) 环境中安装图像处理依赖项时。

¥This ensures that cached files are not added to your git repository – something that is generally not recommended to do unless absolutely necessary. In some cases, you might need to check in cached files, e.g. when you need to pre-generate social cards locally, e.g., when you're not be able to install the image processing dependencies in your continuous integration (CI) environment.

在这种情况下,我们建议将cache_dir设置(所有实现缓存的插件共享的设置)更改为添加到 git 存储库的文件夹。

¥In this case, we recommend changing the cache_dir setting – something that all plugins that implement caching share – to a folder which you add to your git repository.