Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This package led to can't cache images output by spatie/laravel-glide #20

Open
argb opened this issue Nov 21, 2015 · 1 comment
Open

Comments

@argb
Copy link

argb commented Nov 21, 2015

These days I am trying image processing,and tried spatie/laravel-glide base on http://glide.thephpleague.com/, and at the same time I used your httpcache pakage.
what make me crazy is no matter how to try images can't be cached by browers.
spended lots of time ,finally i found that every time I send a request to server,the below function in symfony Response:
public function isNotModified(Request $request)
{
if (!$request->isMethodSafe()) {
return false;
}

    $notModified = false;
    $lastModified = $this->headers->get('Last-Modified');
    $modifiedSince = $request->headers->get('If-Modified-Since');

    if ($etags = $request->getETags()) {
        $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
    }

    if ($modifiedSince && $lastModified) {
        $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
    }

    if ($notModified) {
        $this->setNotModified();
    }

    return $notModified;
}

was called twice.

[2015-11-21 07:54:05] local.INFO: Cache-Control: max-age=31536000, public
Content-Length: 12120
Content-Type: image/jpeg
Date: Sat, 21 Nov 2015 07:54:05 GMT
Expires: Mon, 21 Nov 2016 07:54:05 GMT
Last-Modified: Sat, 21 Nov 2015 05:26:38 GMT

[2015-11-21 07:54:05] local.INFO: Cache-Control: private
Content-Type: text/html; charset=UTF-8
Date: Sat, 21 Nov 2015 07:54:05 GMT
X-Symfony-Cache: GET /img/greatwall?filt=greyscale&q=60&s=f731d23929793b5021f7a00c0ab6c855&w=300: miss

Then I removed http-cache related middleware,It worked,got 304 and isNotModified only called once,
[2015-11-21 07:56:47] local.INFO: Cache-Control: max-age=31536000, public
Content-Length: 12120
Content-Type: image/jpeg
Date: Sat, 21 Nov 2015 07:56:47 GMT
Expires: Mon, 21 Nov 2016 07:56:47 GMT
Last-Modified: Sat, 21 Nov 2015 05:26:38 GMT

httpcache cased that can't get
$lastModified = $this->headers->get('Last-Modified');
$modifiedSince = $request->headers->get('If-Modified-Since');
at same time. So every time isNotModified() executed,return false.

I haven't research why httpcache package cased the problem,you could give me some explanation ,thank you very much .
I use this link to test ,
http://www.bigfeettrip.com/img/greatwall?w=300&q=60&filt=greyscale&s=f731d23929793b5021f7a00c0ab6c855

@argb
Copy link
Author

argb commented Nov 21, 2015

It seems that all request missed cache,the cache directory is empty,and it has write permission.So maybe that means this package don't work in fact,so every time missed,then fetch it and changed the original header,so images can't cached by browser too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant