FotoGrids can cache the rendered HTML output of each Gallery, storing it in the database so that repeat visitors receive a pre-built response rather than a freshly rendered one. Enabling the cache reduces server processing on every page load and speeds up gallery delivery for sites with high traffic or complex layouts.
Location Gallery Settings → Performance → Caching
How Gallery Caching Works #
When caching is enabled, FotoGrids renders the gallery HTML once and stores it — along with the CSS and JS asset references it needs — in a dedicated database table. On subsequent page loads, FotoGrids reads from that table instead of re-rendering. If a persistent object cache (such as Redis or Memcached) is active on the server, FotoGrids also stores the entry in memory for even faster retrieval.
The cache is keyed by the Gallery’s settings, its item list, any shortcode attributes, and the FotoGrids version — so updating the plugin invalidates every stored entry. A change to any of those — editing an item, reordering, changing a setting, or importing — automatically invalidates the Gallery’s cache. The next visitor triggers a fresh render, which is then stored again.
The key also carries a bucket, filterable through fotogrids/cache/bucket, so output that varies by visitor context — a Gallery limited to registered users, for example — is stored separately rather than shared.
Users with the manage_fotogrids or edit_fotogrids_galleries capability always bypass the cache and see live output, as do WordPress preview requests. The cache is served only to regular visitors.
Settings #
Enable Cache
| Setting | Enable Gallery Cache |
| Options | On Off |
| Default | On |
Turns caching on or off for this Gallery. When off, every page load renders the gallery fresh from the database.
Cache Duration
| Setting | Cache Duration |
| Range | 1–168 |
| Units | hours |
| Default | 24 |
| Visible when | Enable Gallery Cache is on |
How long a cached entry remains valid before FotoGrids discards it and renders a fresh copy on the next request. Set a shorter duration if the Gallery’s content changes frequently; longer durations reduce database reads on stable content.
Cache Status
When caching is enabled, a Cache Status indicator appears showing when the current cache entry was created and when it expires. This is informational only — no action is required. If the cache has not yet been built (for example, immediately after enabling the setting), the indicator shows that no valid cache entry exists.
What Invalidates the Cache #
FotoGrids automatically clears a Gallery’s cache when any of the following happen:
- An item is added, removed, or has its metadata updated
- The item order is changed
- Gallery settings are saved
- A gallery is imported
- The Gallery is deleted
No manual cache-clearing is needed after routine edits. For site-wide cache flushes (for example, after a plugin update), FotoGrids exposes the fotogrids/cache/flushed_all action that third-party caching plugins can hook into.
When to Enable Caching #
Caching is most beneficial on Galleries that receive significant traffic relative to how often their content changes, use complex layouts that take measurable time to render, or are embedded on high-traffic landing pages or homepages.
For Galleries that are edited frequently throughout the day, a short cache duration (1–4 hours) or leaving the cache off may be more appropriate.
This cache and your site’s page cache #
Everything on this page describes the FotoGrids cache, which stores rendered Gallery HTML in the database and is the one cache the plugin owns. A caching plugin, your host, or a CDN stores the whole page separately, and FotoGrids cannot switch those off — it can only ask them to skip a page.
Two filters draw that line. fotogrids/cache/should_cache decides whether FotoGrids stores its own render. fotogrids/cache/bypass_page_cache decides whether the response asks host, page-builder and CDN caches not to store the page, by defining DONOTCACHEPAGE and sending Cache-Control: no-store.
Random sorting is the one setting that skips this cache
A Gallery whose Default Sort Order is Random and whose Randomize Order is set to Random on every request bypasses the FotoGrids cache entirely, whatever Enable Gallery Cache says — a stored render cannot give a new order per request. The other two Randomize Order modes leave caching untouched and resolve the order in the visitor’s browser instead. See Random Sort and Caching.