Configuration | laravel-responsecache | Spatie       

 SPATIE  

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

spatie.be/open-source

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

 Version   v8      

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

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

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

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

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

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

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

###  On this page 

1. [ Cache store ](#content-cache-store)
2. [ Cache lifetime ](#content-cache-lifetime)
3. [ Minimum requests before caching ](#content-minimum-requests-before-caching)
4. [ Disabling the cache ](#content-disabling-the-cache)
5. [ Ignored query parameters ](#content-ignored-query-parameters)
6. [ Excluded request headers ](#content-excluded-request-headers)
7. [ 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
```

Minimum requests before caching
-----------------------------------------------------------------------------------------------------------------------------------------------------

By default, every cacheable response is stored on its first request. When a large share of your traffic consists of URLs that are requested only once, such as crawlers walking through a catalog, those responses fill the cache without ever being served from it.

You can require a page to be requested a number of times before its response is stored. This works like the `proxy_cache_min_uses` directive in nginx.

```
RESPONSE_CACHE_MINIMUM_REQUESTS=2
```

Requests are counted once per cache key per HTTP request, including when cache middleware overlaps. A request only counts when its response could have been cached, so an error response does not bring a page closer to the minimum. Fresh cache hits do not increment the counter. This setting applies to both regular and flexible response caching, including background refreshes of stale responses.

The counters expire after one day by default. The window starts with the first cacheable request and is not extended by later requests. A page must reach the minimum within that window, otherwise the count starts over.

```
RESPONSE_CACHE_MINIMUM_REQUESTS_LIFETIME=86400
```

The counters live on the response cache store. When that store evicts entries under memory pressure, the counters are usually the first to go and a page may never reach the minimum. You can keep them on a separate store:

```
RESPONSE_CACHE_MINIMUM_REQUESTS_STORE=redis
```

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.

Excluded request headers
--------------------------------------------------------------------------------------------------------------------------------

Requests containing any of the configured headers bypass both cache reads and writes, for both regular and flexible caching, regardless of the cache profile. By default, this skips Livewire and Inertia requests so they cannot receive a cached full-page response instead of the response they expect. Header names are case-insensitive; only their presence matters, not their value.

```
// config/responsecache.php

'excluded_request_headers' => [
    'X-Livewire',
    'X-Livewire-Navigate',
    'X-Inertia',
],
```

You can add your own headers to this list, or set it to an empty array to disable the check.

Removing a header does not automatically make those requests safe to cache. If a URL can return different responses depending on request headers, use a custom [request hasher](/docs/laravel-responsecache/v8/advanced-usage/customizing-the-hasher) to keep those responses separate. The default cache profile also continues to exclude AJAX requests identified by `X-Requested-With: XMLHttpRequest`.

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`)

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
