| @@ -45,17 +45,27 @@ | ||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Append Cache_control and Access-Control to response ( $next( $request ) ) |
| 48 | 48 | if( $module === 'browser' ){ |
| 49 | + $response = $next( $request ); | |
| 50 | + | |
| 49 | 51 | // To flush cache we dont set cache-control and let WordPress send nocache headers |
| 50 | 52 | if( $this->hasForceFlush( $request ) ){ |
| 51 | - return $next( $request ); | |
| 53 | + return $response; | |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | - // disable WordPress nocache header for this request | |
| 55 | - add_filter( 'nocache_headers', 'depicter_disable_nocache_headers' ); | |
| 56 | + $responseBody = $response->getBody()->getContents(); | |
| 57 | + if ( JSON::isJson( $responseBody ) ) { | |
| 58 | + $responseArray = JSON::decode( $responseBody, true ); | |
| 59 | + if ( isset( $responseArray['errors'] ) ) { | |
| 60 | + return $response; | |
| 61 | + } | |
| 62 | + } | |
| 56 | 63 | |
| 57 | - return $next( $request )->withHeader( 'Cache-Control', 'max-age=' . $expiration ) | |
| 64 | + // disable WordPress nocache header for this request | |
| 65 | + add_filter( 'nocache_headers', 'depicter_disable_nocache_headers' ); | |
| 66 | + | |
| 67 | + return $response->withHeader( 'Cache-Control', 'max-age=' . $expiration ) | |
| 58 | 68 | ->withHeader( 'Access-Control-Allow-Origin' , '*' ); |
| 59 | 69 | } |
| 60 | 70 | |
| 61 | 71 | $cache = \Depicter::cache( $module ); |