Caching May 26, 2013 / Updated: June 12, 2022
How caching works
Zenphoto does not touch the original full images you uploaded to the albums directory. But it does cache the resized images like thumbs, sized large images or any other sized images so they don't have to be generated again.
Zenphoto also caches sized images if they have the same size of the original full image. It does this to prevent overhead checking this everytime if it needs to be cached. If available on your server Zenphoto will use symlinks to those already sized instead of copying the image again (unless a watermark is set).
Zenphoto generally creates these cached files on the fly. This means they are not preliminary created but on request, e.g. if someone visits a page of your site. Depending on the dimensions of your images and your server's power this might result in an initial delay once. Other systems create fixed predefined sizes on upload but this allows Zenphoto themes to flexible use all kinds of different image sizes.
These cached images are stored in the root /cache folder. You can clear this cache manually on the backend if you have the cache_manager plugin enabled. It is for obvious reasons not possible to disable this cache.
Also see below: Pre-caching images and why it is technically not necessary
Important note: Zenphoto can't create thumbs from multimedia files directly. This is actually a server limitation. Please see here for info about video thumbs.
Zenphoto caches the rss feeds provided as static .xml files in the root /cache_html/rss/ folder. This happens on the fly. This cache can be disabled via an option.
Static HTML cache
Optionally there is also the included static_html_cache plugin that caches all pages as static .html files in the /cache_html folder. This also happens on the fly when a page is visited matching the search expire setting. If you use the multilingual option a page for each language is generated automatically.
Caching excludes password.php, 404.php error pages and pages with comments plus those you excluded on the plugin's options. A cached page is also not created if the page is not static, e.g. includes links to uncached images (image processor links) or if you are loggedin with appropiate rights.
Note: The cache needs to be cleared if you change anything and want it to appear it instantly before the expire date set is reached. It is not autocleared when saving an update to any page. This is to avoid conflicts if content is called outsite the page itself (e.g. front page) that could not be covered because it is not known.
If you have enabled the sitemap-extended plugin the sitemap is cached in /cache_html/sitemap as a static .xml file as well. This cache is not created on the fly and does not update itself. Instead you have to generate it manually from from the admin overview page's utility. This is to avoid unwanted overhead as this cache goes through through your complete site.
This cache cannot be disabled.
The built-in search engine also optionally caches search queries in the database table search_cache to speed up search results. Once the expiration interval is reached cached queries are deleted respectively updated so they are alway up to date.
The table can grow over the time and if you hit the utility button "database refresh" it is cleared. It is also cleared whenever you copy/move/delete any item. If you have enabled the cache_manager plugin you can also clear this cache directly.
Pre-caching images and why it is technically not necessary
Zenphoto was designed to lazy-load images to allow a gallery of unlimited size while still allowing viewing any image at any time regardless of whether it has been processed or not. It does it on the fly. It was not designed to process them all at once, the pre-caching was a hack that was added on later. The diagram above shows the process.
Better to leave them be, let the gallery work as it is, and process them when they're first requested. For users, this will mean a very slight delay the first time an image is *ever* viewed, and absolutely none after that. This is how Zenphoto is designed to work, and we think how it works best. No need to pre-cache anything, just quit worrying about the initial lag from the first processing, it only happens once.
Why are images of the correct size still cached additionally?
Once-upon-a-time the image was not cached for display on the single image display (image.php) if the size is already the needed size. Remember Zenphoto's albums are file system based so there was a serious problem with that strategy. Caching an image happens only once per "size" and takes some disk space. Testing to see if the image should be cached happens every time the image is referenced for display in any way.
So the trade-off is storage space vs. processing overhead. With the cost of disk so low these days the choice is a no-brainer.
If you want no processiong/caching you need to modify your theme's image.php to use the full image directly.
This text by www.zenphoto.org is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Code examples are released under the GPL v2 or later license
For questions and comments please use the forum or discuss on the social networks.