Answer the question
In order to leave comments, you need to log in
Why doesn't Intervention Image Cache cache images?
For a site on Laravel 5.3, I installed the Intervention Image Cache plugin for caching images, published configs, set paths.
Made a route for pictures. The problem is that every time I access the image through this route, as I understand it again, it is cut off and cached, although the image should already be in the cache, and accordingly, all images on the site are loaded for a long time, although their size is 30-100 KB.
The solution with setting the response , for caching on the browser side does not change anything ...
Here is my code where I cache images:
$img = Image::cache(function($image) use($path) {
return $image->make($path)->resize(420, 360);
}, 43200, false);
$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $img);
return new IlluminateResponse($img, 200, [
'Content-Type' => $mime,
'Cache-Control' => 'max-age=' . 43200) . ', public',
'Etag' => md5($img)
]);
Answer the question
In order to leave comments, you need to log in
Here I look at such caching attempts and it just causes me bewilderment. Are you seriously going to pull php for every request for a picture?
If you want to resize images automatically, then cache through nginx, and through this useless cache function
fastcgi_cache_path /home/www/nginx levels=1:2 keys_zone=CACHE:256m max_size=100m inactive=100d;
server {
server_name domain.ltd;
listen 80;
location ~ /image/resize/([0-9]+) {
fastcgi_cache CACHE;
fastcgi_cache_key "domain.ltd$request_uri";
fastcgi_cache_use_stale updating error timeout http_500;
fastcgi_cache_valid 200 302 304 30d;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
add_header X-Cache $upstream_cache_status;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/domain.ltd/public/index.php;
include fastcgi_params;
$img = Image::make($path)->resize(420, 360);
return $img->response('jpg');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question