Back to Dagger

Invalidate Cache

docs/current_docs/partials/cookbook/builds/_invalidate-cache.mdx

0.20.71.5 KB
Original Source

Invalidate cache

The following function demonstrates how to invalidate the Dagger layer cache and force execution of subsequent workflow steps, by introducing a volatile time variable at a specific point in the Dagger workflow.

:::note

  • This is a temporary workaround until cache invalidation support is officially added to Dagger.
  • Changes in mounted cache volumes or secrets do not invalidate the Dagger layer cache. :::
<Tabs groupId="language" queryString="sdk"> <TabItem value="go" label="Go">
go
</TabItem> <TabItem value="python" label="Python">
python
</TabItem> <TabItem value="typescript" label="TypeScript">
typescript
</TabItem> <TabItem value="php" label="PHP">
php
</TabItem> </Tabs>

Example

Print the date and time, invalidating the cache on each run. However, if the CACHEBUSTER environment variable is removed, the same value (the date and time on the first run) is printed on every run.

<Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c build ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." build ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call build ``` </TabItem> </Tabs>