Configuration | laravel-responsecache-go | Spatie       

 SPATIE  

laravel-responsecache-go
========================

spatie.be/open-source

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

 Version   v1      

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

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

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

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

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

- [ Custom cache profiles ](https://spatie.be/docs/laravel-responsecache-go/v1/advanced-usage/custom-cache-profiles)
- [ Creating a replacer ](https://spatie.be/docs/laravel-responsecache-go/v1/advanced-usage/creating-a-replacer)
- [ Customizing the serializer ](https://spatie.be/docs/laravel-responsecache-go/v1/advanced-usage/customizing-the-serializer)
- [ Customizing the hasher ](https://spatie.be/docs/laravel-responsecache-go/v1/advanced-usage/customizing-the-hasher)
- [ Configuration ](https://spatie.be/docs/laravel-responsecache-go/v1/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)
8. [ Configuration fields ](#content-configuration-fields)
9. [ Differences from PHP ](#content-differences-from-php)

Configure the package with environment variables and callbacks passed to `responsecache.New`. Callbacks run last. Settings belong to each application, not to a global singleton.

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

By default, Laravel's configured cache store is used. You can select another registered store with `RESPONSE_CACHE_DRIVER=redis`. Tags work with every store, not only stores with native tag support. Use a shared store for multiple server processes and console invalidation.

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

The default cache lifetime is one week (604800 seconds). Change it with `RESPONSE_CACHE_LIFETIME=3600` or `Config.Lifetime = time.Hour`.

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

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

Set `RESPONSE_CACHE_MINIMUM_REQUESTS=2` to require a second eligible request. This works like nginx's `proxy_cache_min_uses`. Counters expire after one day. The window starts with the first eligible response and is not extended by later requests. Configure the window with `RESPONSE_CACHE_MINIMUM_REQUESTS_LIFETIME` and a separate counter store with `RESPONSE_CACHE_MINIMUM_REQUESTS_STORE`.

Requests count once per key per HTTP request, even with overlapping middleware. Failed responses and fresh hits do not count. The threshold also applies to stale refreshes.

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

Set `RESPONSE_CACHE_ENABLED=false` to disable response caching entirely.

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

`IgnoredQueryParameters` defaults to `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`, `gclid` and `fbclid`. Other parameters remain part of the key. Query names are sorted and repeated values are preserved. Set the slice to nil to ignore no parameters.

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

`ExcludedRequestHeaders` defaults to `X-Livewire`, `X-Livewire-Navigate` and `X-Inertia`. Their presence bypasses reads and writes. Use an empty slice to disable the check. If these requests return different content, partition them with a custom hasher before allowing them into the cache.

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

`APP_DEBUG=true` enables diagnostic headers by default. `Debug.Time`, `Status`, `Age` and `Key` default to `X-Cache-Time`, `X-Cache-Status`, `X-Cache-Age` and `X-Cache-Key`. An empty name disables that header. Time and age appear on hits. The key also requires Laravel's `APP_DEBUG` to be enabled.

Configuration fields
--------------------------------------------------------------------------------------------------------------------

Config fieldEnvironmentDefaultEnabledRESPONSE\_CACHE\_ENABLEDtrueStoreRESPONSE\_CACHE\_DRIVERLaravel's CACHE\_STORELifetimeRESPONSE\_CACHE\_LIFETIME604800 secondsTagsRESPONSE\_CACHE\_TAGnoneMinimumRequestsRESPONSE\_CACHE\_MINIMUM\_REQUESTS1MinimumRequestsLifetimeRESPONSE\_CACHE\_MINIMUM\_REQUESTS\_LIFETIME86400 secondsMinimumRequestsStoreRESPONSE\_CACHE\_MINIMUM\_REQUESTS\_STOREresponse storeBypassHeaderCACHE\_BYPASS\_HEADER\_NAMEemptyBypassValueCACHE\_BYPASS\_HEADER\_VALUEemptyDebug.EnabledAPP\_DEBUGfalseGo lifetime fields use `time.Duration`. Environment lifetimes use integer seconds. Invalid typed environment values stop startup. Negative lifetimes, nonpositive counter windows and minimum counts below one are rejected. A zero lifetime disables cache reads and writes.

The replaceable defaults are `Profile: DefaultProfile{}`, `Hasher: DefaultHasher{}`, `Serializer: JSONSerializer{}` and `Replacers: []Replacer{CSRFTokenReplacer{}}`. Use these explicit configuration fields instead of registering another service with the same type. The framework beta returns the first matching service registration.

Differences from PHP
--------------------------------------------------------------------------------------------------------------------

- Go route middleware and groups replace controller attributes, middleware strings and facade calls.
- Manual response seeding and PHP's low-level repository methods are not exposed. Use route middleware for response reads and writes, and the service for invalidation.
- Files and streams remain uncached because Laravel Go does not expose their bodies as buffered response bytes.
- The default store is Laravel's configured cache store. Laravel Go has no built-in file cache store.
- Tags and namespace clearing use generation keys and never flush unrelated application data. Markers expire after one year. Old response bytes keep their original TTL.
- SHA-256 with framed fields replaces xxh128. Keys include the host and port, normalized query, method and user suffix. They are not wire-compatible with PHP or Rust.
- Both serializers preserve arbitrary body bytes. RawBodySerializer still passes through Laravel's outer JSON storage envelope.
- Refresh uses post-response cleanup with a distributed lock rather than PHP's defer API. It is not a queue job and is not durable across crashes.
- There are no configurable models or jobs because this PHP package does not own any. Profiles, hashers, serializers, replacers and cache stores remain replaceable.

Headers, cookies and body inputs do not partition entries by default. If a response varies by language, tenant, permissions or any other input, include it in the profile suffix or hasher. Always keep authorization outside the cache. Do not share private responses merely by returning an empty suffix.

 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)
