[6.x] Hybrid Glide image caching#14570
Open
duncanmcclean wants to merge 6 commits into6.xfrom
Open
Conversation
Contributor
|
🔥 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request implements a new "hybrid" caching strategy for Glide image manipulation.
The Problem
Statamic currently offers two Glide caching modes:
cache: false) — Fast template rendering, but every image request hits PHP, even after the image has already been generated.cache: true) — Images are served directly by the web server, but they're all eagerly generated during template rendering. A page with 10 images × 11 variants = 110 images blocking the page from even loading.Hybrid Caching
Setting
cacheto'hybrid'enables a new mode that combines the best of both:The Glide tag outputs a URL pointing to where the cached image will live, but doesn't generate the image during template rendering. When the browser requests the image:
cache_path, and serves it.After the first request, the web server serves the static file directly on all subsequent requests. The default Nginx/Apache/IIS configurations handle this automatically — no additional rewrite rules are needed.
How It Works
GlideCachePathResolverpredicts the deterministic cache path for an image without generating it.HybridUrlBuilderbuilds clean URLs using the cache path, and stores a mapping in the Glide cache store so the controller knows how to generate the image later.GlideControllerhandles the PHP fallback: it checks if the file already exists (logging a debug message if server rewrite rules aren't configured), looks up the mapping, and generates the image on demand.php please glide:clearwork automatically — the cache disk is the public path, so existing cleanup logic handles it.Closes statamic/ideas#1420
Docs PR: statamic/docs#1899