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, and any shortcode attributes. 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.
Administrators and editors with the manage_fotogrids 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 | Off |
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.