# Cache and about

> Cache the control of each model with access:cache in every deployment, and read the state of the package in the Access Control section of php artisan about.

## Caching the controls

```bash
php artisan access:cache
php artisan access:clear
```

`access:cache` writes the control of each discovered model, and the models that the `reindexWhen()` rules of the controls watch, into `bootstrap/cache`. `access:clear` removes both files.

- `php artisan optimize` runs `access:cache`, and `php artisan optimize:clear` runs `access:clear`.
- The cache is used as it is, the way Laravel uses its route and event caches: run it again in every deployment, after adding, moving or deleting a control, or adding a `reindexWhen()`.
- It runs once every service provider has booted, so it caches the controls of every directory passed to [`Access::discoverControlsIn()`](/essentials/controls#discovery).
- A cached control class that was deleted since is skipped.
- `access:check` reports a stale cache: `stale_control_cache` for the controls, `stale_watch_cache` for the watched models. See [access:check](/testing-and-tooling/access-check#problems).

Without the cache, the package discovers the controls when a model first asks for its control. With Laravel Scout installed, the first Eloquent write of a process also builds the control of every discovered `ControlledSearchable` model, to know which writes reindex which documents: the cache spares that work in production.

## The about command

`php artisan about` prints an "Access Control" section:

```bash
php artisan about --only=access_control
```

```txt
Access Control ................................................................
  Automatic policies ................................................. registered
  Cache .............................................................. not cached
  Controls ................................................................... 12
  Discovery paths .................................................. app/Access/Controls
  Scout ...................................................... installed, meilisearch driver
  Version ........................................................................ 1.0.0
  laravel-rest-api ............................... installed, AccessControlExtension enabled
```

<table>
<thead>
  <tr>
    <th>
      Row
    </th>
    
    <th>
      Value
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        Version
      </code>
    </td>
    
    <td>
      The installed version of the package.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        Controls
      </code>
    </td>
    
    <td>
      The number of controls, read from the cache when it exists, else from the discovery paths. No control is built. When discovery fails, the row reads <code>
        discovery failed:
      </code>
      
       and the first line of the error.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        Discovery paths
      </code>
    </td>
    
    <td>
      Every directory the controls are discovered in, relative to the base path: <code>
        app/Access/Controls
      </code>
      
       first, then the ones added with <code>
        Access::discoverControlsIn()
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        Cache
      </code>
    </td>
    
    <td>
      <code>
        cached
      </code>
      
       when <code>
        access:cache
      </code>
      
       wrote its file, <code>
        not cached
      </code>
      
       otherwise.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        Automatic policies
      </code>
    </td>
    
    <td>
      <code>
        registered
      </code>
      
       after <code>
        Access::registerPolicies()
      </code>
      
      , <code>
        not registered
      </code>
      
       otherwise, or when the application replaced the policy guesser afterwards.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        Scout
      </code>
    </td>
    
    <td>
      <code>
        not installed
      </code>
      
      , or the driver of the environment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        laravel-rest-api
      </code>
    </td>
    
    <td>
      <code>
        not installed
      </code>
      
      , <code>
        AccessControlExtension enabled
      </code>
      
      , or <code>
        AccessControlExtension listed in rest.disabled_extensions
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

- `--json` gives the same rows under the `access_control` key.
- The section is registered when the application runs in the console.
- An empty value prints `none`, and a row that cannot be read prints `unavailable:` with the first line of the error: the section never makes `about` fail.

Add this section when you report an issue.
