From 655d5fbe07ccd2067026d4eb431b88b07fd4373a Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Wed, 1 Jul 2026 11:53:02 +1200 Subject: [PATCH] Make gallery cache time configurable --- app/config.json | 3 ++- app/src/gallery/builder.ts | 8 ++++---- docs/configuration.md | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/config.json b/app/config.json index 2bc0302..7dabf59 100644 --- a/app/config.json +++ b/app/config.json @@ -42,7 +42,8 @@ "singleItemAutoOpen": true, "showTitle": true, "showDescription": false, - "groupByDate": false + "groupByDate": false, + "cacheTime": 300 }, "lightbox": { "showArrows": true, diff --git a/app/src/gallery/builder.ts b/app/src/gallery/builder.ts index 311e6ab..bc78ea1 100644 --- a/app/src/gallery/builder.ts +++ b/app/src/gallery/builder.ts @@ -49,7 +49,6 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb const descriptionInSidebar = shareMetadataAllowed && !!getConfigOption('ipp.showMetadata.description.sidebar', false) const sidebarHasContent = shareMetadataAllowed && (descriptionInSidebar || metadataGroupActive('exif') || metadataGroupActive('location')) - // Build structured items in parallel const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise => { let videoData: string | undefined if (asset.type === AssetType.video) { @@ -159,9 +158,10 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb metaBase } - // Always revalidate the HTML so it picks up new versioned asset URLs on - // upgrade; the assets themselves are immutable-cached. (304s via ETag.) - res.header('Cache-Control', 'no-cache') + // HTML gallery page cache time + const configured = Number(getConfigOption('ipp.gallery.cacheTime', 300)) + const cacheTime = Number.isFinite(configured) ? Math.max(0, configured) : 300 + res.header('Cache-Control', 'public, max-age=' + cacheTime) res.send(renderPage(h(Gallery, props))) } diff --git a/docs/configuration.md b/docs/configuration.md index 6025627..593a036 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -85,6 +85,7 @@ Options that control how the gallery page is rendered. Configured under `ipp.gal | `showTitle` | `bool` | Show a title on the gallery page. This is taken from the album title if it is an album being shared, otherwise the "Description" from the shared link will be used. | | `showDescription` | `bool` | Show the album description below the title. This only applies if it is an album which is being shared. | | `groupByDate` | `bool` | Group the gallery's thumbnails by month, with headers like "December 2024" above each group. Sorts photos newest-first. Items missing a creation date end up under an "Undated" bucket at the end (or render without any header when the whole gallery is undated). **Requires "Show metadata" to be enabled on the share in Immich** - when that's off, Immich strips creation dates from the assets it returns to IPP, so grouping won't work. Default `false`. | +| `cacheTime` | `int` | How long (in seconds) browsers and any CDN may cache the gallery **page** before revalidating. Set this longer to reduce load on your server, but be aware that if you add new photos to a gallery they won't show up until the cache times out or you manually clear any downstream caches. | Example: show the gallery title and group photos by month.