Configuration | laravel-responsecache | Spatie

 SPATIE

  Laravel Response Cache
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-responsecache](https://spatie.be/docs/laravel-responsecache/v8)  Advanced-usage  Configuration

 Version   v8

 Other versions for crawler [v8](https://spatie.be/docs/laravel-responsecache/v8)

- [ Introduction ](https://spatie.be/docs/laravel-responsecache/v8/introduction)
- [ Support us ](https://spatie.be/docs/laravel-responsecache/v8/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-responsecache/v8/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-responsecache/v8/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-responsecache/v8/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-responsecache/v8/changelog)
- [ About us ](https://spatie.be/docs/laravel-responsecache/v8/about-us)

Basic usage
-----------

- [ Caching responses ](https://spatie.be/docs/laravel-responsecache/v8/basic-usage/caching-responses)
- [ Flexible caching (SWR) ](https://spatie.be/docs/laravel-responsecache/v8/basic-usage/flexible-caching)
- [ Preventing caching ](https://spatie.be/docs/laravel-responsecache/v8/basic-usage/preventing-caching)
- [ Clearing the cache ](https://spatie.be/docs/laravel-responsecache/v8/basic-usage/clearing-the-cache)
- [ Using tags ](https://spatie.be/docs/laravel-responsecache/v8/basic-usage/using-tags)
- [ Events ](https://spatie.be/docs/laravel-responsecache/v8/basic-usage/events)

Advanced usage
--------------

- [ Custom cache profiles ](https://spatie.be/docs/laravel-responsecache/v8/advanced-usage/custom-cache-profiles)
- [ Creating a replacer ](https://spatie.be/docs/laravel-responsecache/v8/advanced-usage/creating-a-replacer)
- [ Customizing the serializer ](https://spatie.be/docs/laravel-responsecache/v8/advanced-usage/customizing-the-serializer)
- [ Customizing the hasher ](https://spatie.be/docs/laravel-responsecache/v8/advanced-usage/customizing-the-hasher)
- [ Configuration ](https://spatie.be/docs/laravel-responsecache/v8/advanced-usage/configuration)

 Configuration
=============

###  On this page

1. [ Cache store ](#content-cache-store)
2. [ Cache lifetime ](#content-cache-lifetime)
3. [ Disabling the cache ](#content-disabling-the-cache)
4. [ Ignored query parameters ](#content-ignored-query-parameters)
5. [ Debug headers ](#content-debug-headers)

Cache store
-----------------------------------------------------------------------------------------

By default, the `file` cache driver is used. You can change this to any cache store configured in `config/cache.php`:

```
RESPONSE_CACHE_DRIVER=redis
```

If you use a cache driver that supports tags (like Redis or Memcached), you'll be able to use [cache tags](/docs/laravel-responsecache/v8/basic-usage/using-tags) for more granular cache clearing.

Cache lifetime
--------------------------------------------------------------------------------------------------

The default cache lifetime is one week (604800 seconds). You can change it via the environment variable:

```
RESPONSE_CACHE_LIFETIME=3600
```

Disabling the cache
-----------------------------------------------------------------------------------------------------------------

You can disable response caching entirely:

```
RESPONSE_CACHE_ENABLED=false
```

Ignored query parameters
--------------------------------------------------------------------------------------------------------------------------------

By default, common tracking parameters like `utm_source`, `gclid`, and `fbclid` are stripped from the cache key. This means that `https://example.com/page` and `https://example.com/page?utm_source=google&gclid=abc` will share the same cached response.

You can customize the list of ignored parameters in the config file.

```
// config/responsecache.php

'ignored_query_parameters' => [
    'utm_source',
    'utm_medium',
    'utm_campaign',
    'utm_term',
    'utm_content',
    'gclid',
    'fbclid',
],
```

Set this to an empty array if you want all query parameters to be included in the cache key.

Debug headers
-----------------------------------------------------------------------------------------------

When `APP_DEBUG` is `true`, the package adds debug headers to cached responses. You can customize this behavior.

```
// config/responsecache.php

'debug' => [
    'enabled' => env('APP_DEBUG', false),
    'cache_time_header_name' => 'X-Cache-Time',
    'cache_status_header_name' => 'X-Cache-Status',
    'cache_age_header_name' => 'X-Cache-Age',
    'cache_key_header_name' => 'X-Cache-Key',
],
```

When enabled, cached responses will include the following headers:

- `X-Cache-Status`: `HIT` or `MISS` indicating whether the response was served from cache
- `X-Cache-Time`: the timestamp when the response was cached
- `X-Cache-Age`: how many seconds ago the response was cached (only on cache hits)
- `X-Cache-Key`: the cache key used (only when `app.debug` is `true`)
