# Configuration

The minimum recommended settings for your config.php file:

```php
$config['speedy_enabled'] = 'yes';
$config['speedy_driver'] = 'file';
```

The following are optional:

### Optional Configuration

The following list of `$config` options are all set to the recommended values by default. You can change them based on your site's needs.

```php
$config['speedy_block_bots'] = 'no';
```

Check the user agent and prevent caching items when a bot is detected.

```php
$config['speedy_break_async'] = 'no';
```

Attempt to break the cache asynchronously when possible. (Default: `"no"`)

```php
$config['speedy_diagnostics_enabled'] = 'no';
```

[Diagnostics](https://docs.boldminded.com/speedy/docs/diagnostics) are enabled by default. Set this to `no` to disable diagnostics. (Default: `"yes"`)

```php
$config['speedy_driver'] = 'dummy';
```

The default driver to use if one is not specified on the module tag. (Default: `"dummy"` Options: (`dummy|database|file|redis|static|memcache|memcached`) You can only have 1 driver set to default at a time.

```php
$config['speedy_driver_fragment'] = 'yes';
```

This lets you cache some pages with the static driver and cache other pages using fragments. A duel setup might look like this in your config file.

```php
$config['speedy_driver'] = 'static';
$config['speedy_driver_fragment'] = 'redis';
```

```php
$config['speedy_enabled'] = 'yes';
```

Set this to `no` to disable Speedy completely.

```php
$config['speedy_enable_refresh'] = 'yes';
```

If set to no will not attempt to refresh any of the cached items, thus no cURL requests behind the scenes to try to re-generate cached items, which can take time depending on the size of the site.

```php
$config['speedy_exclude_404s'] = 'yes';
```

Set this to `no` to cache pages that result in a 404 error. (Default: `"yes"`)

```php
$config['speedy_ignore_action_requests'] = 'no';
```

Set this to `yes` to prevent ACT requests from being cached. This is only necessary if an `{exp:speedy:static}` or `{exp:speedy:fragment}` tag is added to something that gets parsed as a template in an Action request, which is very uncommon. (Default: `"no"`)

```php
$config['speedy_ignore_post_requests'] = 'no';
```

Set this to `yes` to prevent POST requests from being cached.

```php
$config['speedy_msm'] = [
    1 => [ // site_id
        'static_path' => '/var/www/html/static',
        'frontedit_check_url' => 'https://main-site.com/?ACT=123',
    ],
    2 => [ // site_id
        'static_path' => '/var/www/html/static-site-two',
        'frontedit_check_url' => 'https://site-two.com/?ACT=123',
    ],
];
```

This is a new config option added in 1.15. It is designed to help assist when configuring Speedy for MSM sites. For example if a key, such as `static_path` is defined in the array for a site it will override the `$config['speedy_static_path']` config value. Only `static_path` and `frontedit_check_url` values are supported as site specific overrides. If you define different values for `static_path` Speedy will place static cache files in the respective directory defined for the site. It will also duplicate the `utilities` folder normally found in the static directory. In most cases the only override necessary, if you're using ExpressionEngine's Frontedit feature, is setting the `frontedit_check_url` URL. Using separate folders for `static_path` is not required, but simply provided if you want cleaner separation of the cache files and utilities folders for each site.

```php
$config['speedy_logged_in_only'] = 'no';
```

Prevent caching items when the visitor is logged in.

```php
$config['speedy_logged_out_only'] = 'no';
```

Prevent caching items when the visitor is logged out.

```php
$config['speedy_query_cache_allowlist'] = [];
```

Add an array of `$_GET` keys that are valid when caching a static page.

```php
$config['speedy_refresh_curl'] = 'yes';
```

Set this to `no` to disable cURL drivers when refreshing the cache.

```php
$config['speedy_refresh_async'] = 'yes';
```

Attempt to refresh the cache asynchronously when possible.

```php
$config['speedy_refresh_exec'] = 'yes';
```

Set this to `no` to disable exec drivers when refreshing the cache. Exec drivers attempt to use PHP's `exec()` function to perform refreshes.

```php
$config['speedy_refresh_interval'] = 0;
```

The number of seconds to sleep between refreshing cache items.

```php
$config['speedy_secret'] = '';
```

A secret passphrase used to authenticate request to ACTion urls. (Default: `""`)

```php
$config['speedy_static_path'] = '[document root]/static';
```

The path to the static file cache directory. `[document root]` is determined by either `$_SERVER['DOCUMENT_ROOT']` or ExpressionEngine's `FCPATH` . **If you are using the Queue module to clear cache via queue jobs, you will want to set this variable to the correct static path.** The queue jobs run in the command line and determines the path differently. This will ensure your cache clearing jobs for static files succeed.

```php
$config['speedy_static_enabled'] = 'no';
```

Set this to `yes` to enable the static file cache.

```php
$config['speedy_static_use_html_file'] = 'no';
```

Set this to `yes` to save static cache files as `.html` files.  By default Speedy saves the static cache files as `.php` files, with the contents of the page stored in the file, along with logic to handle redirects, CSRF tags, and custom headers. In some rare cases the encoding/escaping used to save the page contents in the `.php` file can cause parsing issues. Enabling this option will instead save the actual contents of the page as a basic `.html` file along side the `.php` file, which will still be used to handle redirects, custom headers etc. If the `.html` file is present, the `.php` file will use it's content instead of what is in the `.php` file.

{% hint style="warning" %}
There is a very high likelihood the `speedy_static_use_html_file` default value will be changed to `yes` to enable the accompanying `.html` file in new installations in a future release as default behavior.
{% endhint %}

```php
$config['speedy_ttl'] = 3600;
```

The default TTL in seconds to use if one is not specified on the module tag. Set this to `0` to cache items until the cache it broken.

```php
$config['speedy_disable_category_cache_breaking'] = 'no';
```

This will disable the action that will clear cached items based on category cache breaking rules when a category is saved or deleted.

```php
$config['speedy_use_queue'] = 'no';
```

If the [Queue](https://boldminded.com/add-ons/queue) module is installed, tell Speedy to queue all cache breaking and url refreshing actions.

### Driver Configuration

Speedy has some drivers that are configurable, thus they require extra configuration. The Redis and Memcached drivers require server connections. All configurable drivers have a control panel page to manage their settings, however, you can also manage those settings in your `config.php` file. Below are examples of config file overrides for the Static and Redis drivers.

The Static driver does not have configuration, other than `speedy_static_path` and `speedy_static_enabled`, but you may choose to define some url paths that are to be ignored when caching. Note that ignores can be valid regular expressions.

The Redis driver has additional configuration to manage it's connection to the Redis server. Note that Speedy currently only supports 1 Redis server.

```php
$config['speedy_redis_settings'] = [
    'static' => 'yes',
    'servers' => [
        [
            // You can also use a socket connection, e.g. /tmp/redis.sock as the host value.
            // If you use a socket connection, set port to 0.
            'host' => '127.0.0.1',
            'port' => '6379',
            'timeout' => '0',
            'password' => null,
            
            // These are optinal values if you're using a more advanced setup.
            'database' => '',
            'prefix' => '',
        ]
    ],
    'ignore_urls' => [
        ['url' => 'invalid/page'],
        ['url' => '^[a-z]{2}/products'],
        ['url' => '^products/.*'],
    ],
];
```

Similarly, the Memcached settings can be managed in your config file as well.

```php
$config['speedy_memcached_settings'] = [
    'persistent' => 'yes',
    'servers' => [
        [
            'host' => '127.0.0.1',
            'port' => '6379',
            'weight' => '0',
        ]
    ],
];
```

### Ignoring URLs

You can ignore URLs by not adding the `{exp:speedy:static}` tag to a template, but in the event you need it in the template for one use case, but want to exlude caching that page in a different use case where the same template is applied, you can use the following setting.

```php
$config['speedy_static_settings'] = [
    'ignore_urls' => [
        ['url' => 'invalid/page'],
        ['url' => '^[a-z]{2}/products'],
        ['url' => '^products/.*'],
    ],
];
```

You can still optionally wrap the `{exp:speedy:static}`  tag in a conditional.

```markup
{if segment_1 != "something"}
    {exp:speedy:static}
{/if}
```

### Environment Config

*Added in v1.14.0*

If you are using the `.env.php` file you can configure Redis and Memcahced using environment variables.

```bash
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_USERNAME=null
REDIS_PASSWORD=null
REDIS_DATABASE=1
```

In the control panel, prefix the variable name with a `$` to indicate to Speedy that it should load the value from the `.env.php` file if present.

This option is only available for connection settings. You can not define Ignored URLs through the environment config.

<figure><img src="https://3476660910-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ly1eNBG1JvS5rivVtg3%2Fuploads%2FXPVbhIiH8J2Jc7DXhv3f%2Fspeedy-redis-env-config.png?alt=media&#x26;token=f99cb953-96f9-4067-865b-3207354c4059" alt=""><figcaption></figcaption></figure>
