public function cacheAction($filename)
    {
        $filePath = $this->getParameter('kernel.root_dir').'/../var/storage/cache/'.$filename;
        if (!file_exists($filePath)) {
            return new Response('File not found.', 404);
        }
        $file = file_get_contents($filePath);

        $headers = array();
        if (preg_match('/.png$/', $filename)) {
            $headers = array(
                'Cache-Control'     => 'max-age=3600',
                'Content-Type'     => 'image/png',
                'Content-Disposition' => 'inline; filename="'.$filename.'"',
            );
        } elseif (preg_match('/.jpg/', $filename)) {
            $headers = array(
                'Cache-Control'     => 'max-age=3600',
                'Content-Type'     => 'image/jpg',
                'Content-Disposition' => 'inline; filename="'.$filename.'"',
            );
        } elseif (preg_match('/.pdf/', $filename) || preg_match('/.xlsx/', $filename)) {
            $headers = array(
                'Cache-Control'     => 'private',
                'Content-Type'     => mime_content_type($filePath),
                'Content-length'     => filesize($filePath),
                'Content-Disposition' => 'attachment; filename="'.$filename.'"',
            );
        }

        return new Response($file, 200, $headers);
    }
public function cacheAction($filename)
    {
        $filePath = $this->getParameter('kernel.root_dir').'/../var/storage/cache/'.$filename;
        if (!file_exists($filePath)) {
            return new Response('File not found.', 404);
        }
        $file = file_get_contents($filePath);

        $headers = array();
        if (preg_match('/.png$/', $filename)) {
            $headers = array(
                'Cache-Control'     => 'max-age=3600',
                'Content-Type'     => 'image/png',
                'Content-Disposition' => 'inline; filename="'.$filename.'"',
            );
        } elseif (preg_match('/.jpg/', $filename)) {
            $headers = array(
                'Cache-Control'     => 'max-age=3600',
                'Content-Type'     => 'image/jpg',
                'Content-Disposition' => 'inline; filename="'.$filename.'"',
            );
        } elseif (preg_match('/.pdf/', $filename) || preg_match('/.xlsx/', $filename)) {
            $headers = array(
                'Cache-Control'     => 'private',
                'Content-Type'     => mime_content_type($filePath),
                'Content-length'     => filesize($filePath),
                'Content-Disposition' => 'attachment; filename="'.$filename.'"',
            );
        }

        return new Response($file, 200, $headers);
    }
public function cacheAction ( $ filename ) { $ filePath = $ this -> getParameter ( 'kernel.root_dir' ) . '/../var/storage/cache/' . $ filename ; if ( ! file_exists ( $ filePath ) ) { return new Response ( 'File not found.' , 404 ) ; } $ file = file_get_contents ( $ filePath ) ; $ headers = array ( ) ; if ( preg_match ( '/.png$/' , $ filename ) ) { $ headers = array ( 'Cache-Control' => 'max-age=3600' , 'Content-Type' => 'image/png' , 'Content-Disposition' => 'inline; filename="' . $ filename . '"' , ) ; } elseif ( preg_match ( '/.jpg/' , $ filename ) ) { $ headers = array ( 'Cache-Control' => 'max-age=3600' , 'Content-Type' => 'image/jpg' , 'Content-Disposition' => 'inline; filename="' . $ filename . '"' , ) ; } elseif ( preg_match ( '/.pdf/' , $ filename ) || preg_match ( '/.xlsx/' , $ filename ) ) { $ headers = array ( 'Cache-Control' => 'private' , 'Content-Type' => mime_content_type ( $ filePath ) , 'Content-length' => filesize ( $ filePath ) , 'Content-Disposition' => 'attachment; filename="' . $ filename . '"' , ) ; } return new Response ( $ file , 200 , $ headers ) ; }
Get the cache file

@param string $filename

@return Response A Response instance
Get the cache file