How long are re-sized images cached?
Permalink
In the past, you obviously wanted to make sure your pictures were the correct size. Uploading a huge image and re-sizing it down with HTML was (and still is) a bad idea.
Things like Concrete5 complicate that thinking a bit, though, since Concrete5 will actually create an image of the correct size.
My question: How long is the image cached? I'm not sure which cache setting this follows, if any, or if it is smart enough generate the image once and use it indefinitely until the image changes?
The reason I ask is that often the same image is used in a few different locations around a website, and each location might required a different size. Uploading one master and -setting- the correct size in C5 seems much easier, but if I'm forcing my server to generate a ton of images every couple hours, then I'm not keeping things optimized at all. If it's smart enough to use the same image indefinitely until the original changes, then it seems okay to do.
Thanks!
Things like Concrete5 complicate that thinking a bit, though, since Concrete5 will actually create an image of the correct size.
My question: How long is the image cached? I'm not sure which cache setting this follows, if any, or if it is smart enough generate the image once and use it indefinitely until the image changes?
The reason I ask is that often the same image is used in a few different locations around a website, and each location might required a different size. Uploading one master and -setting- the correct size in C5 seems much easier, but if I'm forcing my server to generate a ton of images every couple hours, then I'm not keeping things optimized at all. If it's smart enough to use the same image indefinitely until the original changes, then it seems okay to do.
Thanks!
The re-sized images are not cached. They are stored in [root]/files/thumbnails. The numbered folders that eventually lead to the image file itself are basically a cut up timestamp. I believe the system creates a new thumbnail each time a block changes the dimensions of the image it requires. The Content block, however, doesn't use this feature and serves up the original image but sized once it's in the browser. This is great and sets concrete5 apart from most other CMS's but it also means that it accumulates old, unused image files on your server over time.
I've always seen my Image block (and other blocks that have images in them, except for Content) use a "/files/cache/693fa905f06d680423c117648d77aac6_f901.jpg" format, not /files/thumbnails/x. I assume the rest of your answer still applies, though?
I've seen pages with large galleries (that still have the same resized image thing going on with /files/cache/) sometimes take 5-10 seconds for the page to begin rendering at all, like the server is generating the thumbnails rapidly, and then a visit hours later results in the same thing happening again. Basically, it has -seemed- to me that the images do expire and require re-generation. This may be flawed thinking, but it's how it seems to be anyway.
Is that explainable? Because I -do- love the idea of it generating the image. I'm just concerned that it has to happen on a continual basis.
I've seen pages with large galleries (that still have the same resized image thing going on with /files/cache/) sometimes take 5-10 seconds for the page to begin rendering at all, like the server is generating the thumbnails rapidly, and then a visit hours later results in the same thing happening again. Basically, it has -seemed- to me that the images do expire and require re-generation. This may be flawed thinking, but it's how it seems to be anyway.
Is that explainable? Because I -do- love the idea of it generating the image. I'm just concerned that it has to happen on a continual basis.
First off let me apologize for leading you astray with the thumbnails concept. Upon digging through the code, I see that my thinking has been wrong on this.
Open up [root]/concrete/core/helpers/image.php and find the getThumbnail() function around line 228.
What appears to happen is that the system uses several different parameters to construct a md5 hash of a 'desired' $filename. Then on line 252, it seeks that $filename in the files/cache/ folder. If it can't find it, it creates a thumbnail by that $filename. Subsequently, whether the file was already there or it had to create a new one, the file is always grabbed from the files/cache/$filename location.
Since concrete5 is an open source project, developers can choose to build galleries any way they want and so there may be some pages in the wild that don't use this capability. Also, sites that are built on different versions of concrete5 will act differently, especially when it comes to caching because those schemes have changed drastically through the years.
As for some galleries taking 5-10 seconds, that may be caused by the slow server or a gallery design that pre-loads all the images before rendering. Hard to tell without seeing the PHP for those slow galleries.
I'm not sure if everyone reading this knows how to check if a large image is being served and then re-sized in the browser so bear with my here if you do. In Chrome, just right-click on an image and choose Inspect Element. Then when you hover over the actual 'src' URL for the image, Chrome will show you the 'natural' size of the image and the client-induced size.
Also, for security reasons, you can see concrete5 'obfuscating' the true location of files on download links. It uses a sort of 'token' that leads to the file so that permissions can be checked before allowing the download.
So I think the answer to your question: 'does the CPU have to re-create new thumbnails on every page refresh' appears to be 'no'. If the getThumbnail() function is being used then the system only creates a specific size once. If someone has deleted all the files in files/cache folder then yes, the first rendering of that gallery will need to re-create all those images again but this is unlikely to affect many visitors. Of course if the getThumbnail() function is not being used then the full size image is being served.
Anyone else out there with more intimate knowledge of these things should certainly chime in!
Open up [root]/concrete/core/helpers/image.php and find the getThumbnail() function around line 228.
What appears to happen is that the system uses several different parameters to construct a md5 hash of a 'desired' $filename. Then on line 252, it seeks that $filename in the files/cache/ folder. If it can't find it, it creates a thumbnail by that $filename. Subsequently, whether the file was already there or it had to create a new one, the file is always grabbed from the files/cache/$filename location.
Since concrete5 is an open source project, developers can choose to build galleries any way they want and so there may be some pages in the wild that don't use this capability. Also, sites that are built on different versions of concrete5 will act differently, especially when it comes to caching because those schemes have changed drastically through the years.
As for some galleries taking 5-10 seconds, that may be caused by the slow server or a gallery design that pre-loads all the images before rendering. Hard to tell without seeing the PHP for those slow galleries.
I'm not sure if everyone reading this knows how to check if a large image is being served and then re-sized in the browser so bear with my here if you do. In Chrome, just right-click on an image and choose Inspect Element. Then when you hover over the actual 'src' URL for the image, Chrome will show you the 'natural' size of the image and the client-induced size.
Also, for security reasons, you can see concrete5 'obfuscating' the true location of files on download links. It uses a sort of 'token' that leads to the file so that permissions can be checked before allowing the download.
So I think the answer to your question: 'does the CPU have to re-create new thumbnails on every page refresh' appears to be 'no'. If the getThumbnail() function is being used then the system only creates a specific size once. If someone has deleted all the files in files/cache folder then yes, the first rendering of that gallery will need to re-create all those images again but this is unlikely to affect many visitors. Of course if the getThumbnail() function is not being used then the full size image is being served.
Anyone else out there with more intimate knowledge of these things should certainly chime in!