# Download cache and cleanup

Reuse downloaded packages between builds and remove cached files when you need disk space.

Source: https://debark.dev/docs/concepts/store-and-incremental

---
Debark keeps downloaded .deb files in a local cache called the **object store**. Later builds
reuse matching files from the store, including downloads made for other bundles.

You don’t need to enable caching. A bundle still contains all the files its target needs,
so it can be copied and used independently of the cache.

## How downloads are reused

Each cached file is identified by its SHA-256 checksum, which is calculated from its contents.
When a build needs a file with that checksum, Debark can reuse the cached copy.

A matching download is skipped. A new package version or a missing cached file is downloaded.
The build may still need internet access to check repositories and resolve the package request.

## Where the store lives

On Linux, the default is `~/.local/share/debark/store`, or under `XDG_DATA_HOME` when set.
Windows uses `%LOCALAPPDATA%\debark\store`.

Use `store_dir` in the [configuration](/docs/reference/configuration) to choose another location.
`DEBARK_STORE` changes the default location when no configured store directory is set.
The store commands also accept `--store PATH`.

For CI, keep this directory between jobs if you want to reuse downloads.

## See what is cached

```bash
debark store ls
```

The listing shows package names, versions, architectures, sizes, and checksums. User-supplied
objects are marked separately because cleanup protects them.

## Refresh an existing bundle

`build --update` refreshes apt indexes and selects current versions for the request. It reuses
cached files where possible and removes superseded bundle files, subject to the pruning rules.

`--no-prune` keeps superseded files. Retained files that aren’t in the current apt index appear
in `last-run-unreferenced.txt`. They take up space but aren’t made available to apt by that index.

See [refreshing bundles](/docs/operate/refreshing) for the full workflow.

## Reclaiming space with store gc

Pass the bundles whose cached files you want to keep, and preview cleanup first:

```bash
debark store gc --dry-run ./bundle-current ./bundle-lab
```

After reviewing the list, run the same command without `--dry-run` to remove the listed objects.

**Include every bundle whose downloads you want to retain.** Debark does not keep a registry
of all your bundles. With no bundle arguments, cleanup protects only user-supplied objects and
removes other cached objects.

Cleanup changes the store, not existing bundle folders. An already assembled bundle remains
usable; a later rebuild may need to download removed objects again.

## Disk space and offline installation

The store and bundle are separate locations. Debark uses hardlinks where possible and copies
otherwise, so allow enough disk space for a full bundle copy.

On the offline machine, apt skips packages already installed at the selected version.
Use `--upgrade` to include the bundle’s additional upgrade set. See
[installing a bundle](/docs/operate/installing).

<NextSteps
  items={[
    {
      title: 'Refresh a bundle',
      href: '/docs/operate/refreshing',
      description: 'Prepare the next set of packages and updates.',
    },
    {
      title: 'Configuration',
      href: '/docs/reference/configuration',
      description: 'Set the cache directory for repeated builds.',
    },
  ]}
/>
