# `Storehouse.Sweeper`
[🔗](https://github.com/hattoriai/storehouse/blob/v0.2.0/lib/storehouse/sweeper.ex#L1)

Sweeps, every `:every` seconds, on a store with no lifecycle rule (the
local disk, MinIO):

  * the temporary files of forms never saved: those under the temporary
    prefix (`Storehouse.cache_prefix/0`) older than `:max_age`;
  * the files that expired (`Storehouse.expiring_key/2`), once their
    time has come;
  * the multipart uploads started more than `:max_age` ago and never
    completed (`Storehouse.presign_multipart/4`), whose parts the store
    keeps (and bills) until they are given up.

On several nodes, each sweep runs on one of them at a time.

    # lib/my_app/application.ex
    children = [
      MyApp.Repo,
      {Storehouse.Sweeper, max_age: 86_400},
      MyAppWeb.Endpoint
    ]

A bucket with lifecycle rules for the prefixes needs none. `sweep/1`
does the same once, for a scheduled job of the app's.

## Options

  * `:max_age` - in seconds. The default is a day.
  * `:every` - in seconds. The default is an hour.
  * `:prefix` - the default is `Storehouse.cache_prefix/0`.
  * `:expiring` - whether expired files are swept. The default is
    `true`.
  * `:multipart` - whether abandoned multipart uploads are given up,
    where the store lists them. The default is `true`.
  * `:adapter` - the store. The default is `Storehouse.adapter/0`.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the sweeper, registered as `Storehouse.Sweeper`.

# `sweep`

```elixir
@spec sweep(keyword()) :: {:ok, non_neg_integer()} | {:error, term()}
```

Deletes, at once, the files under the temporary prefix that are older
than `:max_age` seconds, and the files that expired. Gives
`{:ok, count}`.

Takes `:max_age` (the default is a day), `:prefix` (the default is
`Storehouse.cache_prefix/0`), `:expiring` and `:multipart` (the defaults
are `true`) and `:adapter`. The count is of files and uploads.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
