Search code examples
phplaravelnginxgraphqlapollo

How to remove Cache-control header no-cache


My team and I are working on a Laravel API which communicates with a Vue.js frontend that uses the Apollo client to consume the GraphQL responses.

We have an issue with cache-control headers being added to the response.

Apollo cannot cache the contents because the response contains this header:

Cache-Control: no-cache, private

In php.ini, we have this to disable sending cache-control headers by PHP:

; Set to {nocache,private,public,} to determine HTTP caching aspects
; or leave this empty to avoid sending anti-caching headers.
; http://php.net/session.cache-limiter
session.cache_limiter =

In the nginx config we cannot find anything that is setting those headers. I checked the global nginx.conf and config file we setup in sites/available.

I can add this to the nginx config, but it will only add another header:

add_header Cache-Control "public";

Cache-Control: no-cache, private
Cache-Control: public

If this header is not coming from PHP or nginx, then where could it be coming from? And how can I remove or overwrite it?

  • Laravel 5.5
  • Folkloreatelier/laravel-graphql
  • PHP 7.1
  • nginx 1.14.0
  • Ubuntu 16.04

Solution

  • in any middleware you can use this example

    
        public function handle($request, Closure $next)
        {
            $response = $next($request);
            return $response instanceof \Symfony\Component\HttpFoundation\Response
                ? $response->header('pragma', 'no-cache')
                    ->header('Cache-Control', 'no-store,no-cache, must-revalidate, post-check=0, pre-check=0')
                    ->header('X-ANY-HEADER', 'any header value')
                : $response;
        }
    
    

    but i do not know this fix your problem