Make gallery cache time configurable

This commit is contained in:
Alan Grainger
2026-07-01 11:53:02 +12:00
parent 5c8627b00c
commit 655d5fbe07
3 changed files with 7 additions and 5 deletions
+2 -1
View File
@@ -42,7 +42,8 @@
"singleItemAutoOpen": true, "singleItemAutoOpen": true,
"showTitle": true, "showTitle": true,
"showDescription": false, "showDescription": false,
"groupByDate": false "groupByDate": false,
"cacheTime": 300
}, },
"lightbox": { "lightbox": {
"showArrows": true, "showArrows": true,
+4 -4
View File
@@ -49,7 +49,6 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
const descriptionInSidebar = shareMetadataAllowed && !!getConfigOption('ipp.showMetadata.description.sidebar', false) const descriptionInSidebar = shareMetadataAllowed && !!getConfigOption('ipp.showMetadata.description.sidebar', false)
const sidebarHasContent = shareMetadataAllowed && (descriptionInSidebar || metadataGroupActive('exif') || metadataGroupActive('location')) 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<GalleryItem> => { const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => {
let videoData: string | undefined let videoData: string | undefined
if (asset.type === AssetType.video) { if (asset.type === AssetType.video) {
@@ -159,9 +158,10 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
metaBase metaBase
} }
// Always revalidate the HTML so it picks up new versioned asset URLs on // HTML gallery page cache time
// upgrade; the assets themselves are immutable-cached. (304s via ETag.) const configured = Number(getConfigOption('ipp.gallery.cacheTime', 300))
res.header('Cache-Control', 'no-cache') const cacheTime = Number.isFinite(configured) ? Math.max(0, configured) : 300
res.header('Cache-Control', 'public, max-age=' + cacheTime)
res.send(renderPage(h(Gallery, props))) res.send(renderPage(h(Gallery, props)))
} }
+1
View File
@@ -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. | | `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. | | `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`. | | `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. Example: show the gallery title and group photos by month.