Installation &amp; setup | 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)  Installation &amp; setup

 Version   v1      

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

  Installation &amp; setup    
- [ 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)

 Installation &amp; setup
========================

###  On this page 

1. [ Registering the middleware ](#content-registering-the-middleware)
2. [ Configuring the package ](#content-configuring-the-package)

You can install the package with Go modules.

```
go get github.com/spatie/laravel-responsecache-go@v0.1.0
```

List the package in `bootstrap/app.go`. Installing a Go module does not register it automatically.

```
import (
    "github.com/spatie/laravel-responsecache-go"
    laravel "go.laravel.com"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{responsecache.New()},
    }
}
```

Registering the middleware
--------------------------------------------------------------------------------------------------------------------------------------

Add middleware to the routes you want to cache.

```
route.Get("/posts", posts.Index).Middleware(responsecache.CacheResponse{})
```

By default, this caches successful GET requests returning text or JSON for a week. Use route middleware inside the normal web group, after session and authentication middleware. Authorization, tenant resolution and other checks that must run on every request belong before the cache.

The package installs a small global finalizer to observe the final response, but it never enables caching on its own. If an application prepends other global middleware, place that middleware inside the finalizer when it changes the response. Do not add the cache to both a group and its routes.

Configuring the package
-----------------------------------------------------------------------------------------------------------------------------

Go applications do not publish a PHP config file. Use environment settings or a configuration callback.

```
responsecache.New(func(cfg *responsecache.Config) {
    cfg.Lifetime = 30 * time.Minute
    cfg.Tags = []string{"pages"}
    cfg.MinimumRequests = 3
    cfg.Serializer = responsecache.RawBodySerializer{}
})
```

Callbacks run after the environment is read. Read the [configuration reference](/docs/laravel-responsecache-go/v1/advanced-usage/configuration) for every setting.

 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)
