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

Cache problem if I change max image size after use other one #155

Closed
Hacker12345577342 opened this issue Sep 8, 2016 · 6 comments
Closed

Comments

@Hacker12345577342
Copy link

Hacker12345577342 commented Sep 8, 2016

First I used 700x700 image size then I changed it to 1000x1000 but Glide read image from before cache which is can be onlly max 700x700.I think It was really big issue because if someone wants to increase or decrease max image size it will not work which some companies do more often

@reinink
Copy link
Contributor

reinink commented Nov 14, 2016

This is intended behaviour with Glide, since it wouldn't be very performant if Glide checked the source file on every request. The recommended workaround for this is to simply clear the cached images for that image when it is updated. For example:

$server->deleteCache('kayaks.jpg');

You can read more about that here.

@reinink reinink closed this as completed Nov 14, 2016
@paxperscientiam
Copy link

paxperscientiam commented Nov 16, 2016

Hi @reinink

WRT refreshing the cache, are you no longer recommending adding a dummy parameter to URL?

I ask because, while that method seems to be the easiest, I'm wondering if there might be a more automated way to do this. That is, if I drop a newer version of an image into an assets folder, I'd like Glide to realize that the new image is newer than any of the manipulations stored in cache.

Is this possible with Glide alone?

Thanks.

EDIT: I should mention that adding a dummy parameter does work; however, I could see that this would become impracticable where the number of images is great.

@cdowdy
Copy link

cdowdy commented Dec 14, 2016

sorry about bumping this closed thread but I think I just ran into this problem when using Glide to produce a responsive image set. IE:

<img sizes="100vw"
     srcset="/img/analog-camera-photography-vintage-1844.jpg?w=175 175w ,
       /img/analog-camera-photography-vintage-1844.jpg?w=350 350w ,
       /img/analog-camera-photography-vintage-1844.jpg?w=700 700w ,
       /img/analog-camera-photography-vintage-1844.jpg?w=1400 1400w "
     src="/analog-camera-photography-vintage-1844.jpg?w=175"
     alt="analog-camera-photography-vintage-1844" > 

In a vagrant box running ubuntu 16.04 the image regardless of which one is the source candidate will be whichever was created first. That is if you are on a desktop with a ~1300px wide screen then that would be the 700px image.

So a user on a phone would get the image /img/analog-camera-photography-vintage-1844.jpg?w=350 but it would still be 700px wide. This breaks the purpose of responsive images.

If you're on windows then for some reason each image candidate would be generated (opposite of what happens in the above mentioned vagrant box)

If you add in signatures this causes other havoc as well, that being the image requested wouldn't match the signature of the saved (cached) image .. note: unless I'm horribly misunderstanding or doing something wrong .. if so pleeeeeease tell me haha I've been pulling my hair out for two days now :)

So should we delete in our controller each time a new image is requested with the same name? like you ( @reinink ) mentioned?

/** Example using a symfony style app */
public function connect(Application $app)
{  
  $ctr = $app['controllers_factory'];
  $ctr->get('/{path}', [$this, 'glideImage'])
      ->assert('path', '.+')
      ->bind('glide_thumbs');
  return $ctr;
}  

public function glideImage( $path, $request ) 
{  
  // other things  
  $server->deleteCache($path');
  return $server->getImageResponse($path, $request->query->all());  
}  

Which would negate Glides cache for someone else requesting a different dimension on a different device.

Or should we skip the Image Response part and pull say the width part of the query string, place that in the the file name then save to the cache? Similar to this sitepoint tutorial on glide

@reinink
Copy link
Contributor

reinink commented Dec 16, 2016

@cdowdy Have you tried hitting each individual image endpoint first to see Glide is properly loading each image size? I mean outside of just testing this via the srcset property?

@cdowdy
Copy link

cdowdy commented Dec 16, 2016

hey thanks @reinink !

I did what you suggested and hit each image endpoint separately - images with widths of 200, 350, and 800 - and each image was generated at the correct size.

Then I used srcset and got the correct size for all of them.

I don't know if the size/cached size mismatch happens when there are multiple sizes requested from one image in a session (like a stampede) or if it was just a quirk I came across with this vagrant box and a windows 10 box.

It's super inconsistent. so you might be able to close this again haha! Sorry about this... I'll try to get some better testing done (between a few different environments) eventually and if I come across it again I'll post back here!

Thanks for your time!

@reinink
Copy link
Contributor

reinink commented Dec 16, 2016

That's good at least. You should be able to request 10 different image sizes with Glide at the exact same time and get all the properly sized images. One request should have no bearing on the other request whatsoever.

Good luck! If you do figure out what's wrong in your situation, please report back!

@reinink reinink closed this as completed Dec 16, 2016
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

4 participants