# `NPM.Cache`
[🔗](https://github.com/elixir-volt/npm_ex/blob/v0.7.4/lib/npm/cache.ex#L1)

Global package cache.

Downloaded packages are stored in `~/.npm_ex/cache/<name>/<version>/`
and reused across projects. The cache is populated on first install
and checked before downloading from the registry.

# `cached?`

```elixir
@spec cached?(String.t(), String.t()) :: boolean()
```

Check if a package version is already cached.

# `dir`

```elixir
@spec dir() :: String.t()
```

Root directory of the global cache.

# `ensure`

```elixir
@spec ensure(String.t(), String.t(), String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:ok, :missing_optional} | {:error, term()}
```

Ensure a package version is in the cache.

Downloads and extracts the tarball if not already cached.
Returns `{:ok, cache_path}`, `{:ok, :missing_optional}` when an
optional package fails to fetch, or `{:error, reason}`.

# `package_dir`

```elixir
@spec package_dir(String.t(), String.t()) :: String.t()
```

Path to a specific package version in the cache.

---

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