From 8088df6df473795d018a995a5cf9c0947ee26de1 Mon Sep 17 00:00:00 2001 From: Ian Maddaus Date: Fri, 10 Nov 2023 13:29:08 -0500 Subject: [PATCH] Set age for cached remote resources Signed-off-by: Ian Maddaus --- config.toml | 21 ++++++++++++++ .../layouts/_default/release_notes.html | 29 +++++++++++++++++-- .../layouts/partials/release_notes_toc.html | 21 +++++++++++++- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/config.toml b/config.toml index be272578ba..01cbdd0ad9 100644 --- a/config.toml +++ b/config.toml @@ -60,3 +60,24 @@ notAlternative = true endLevel = 4 ordered = false startLevel = 2 + +[caches] + [caches.assets] + dir = ':resourceDir/_gen' + maxAge = -1 + [caches.getcsv] + dir = ':cacheDir/:project' + maxAge = -1 + [caches.getjson] + dir = ':cacheDir/:project' + maxAge = "1h" + [caches.getresource] + dir = ':cacheDir/:project' + maxAge = "1h" + [caches.images] + dir = ':resourceDir/_gen' + maxAge = -1 + [caches.modules] + dir = ':cacheDir/modules' + maxAge = -1 + diff --git a/themes/docs-new/layouts/_default/release_notes.html b/themes/docs-new/layouts/_default/release_notes.html index 7191c77d4b..5bb46ad191 100644 --- a/themes/docs-new/layouts/_default/release_notes.html +++ b/themes/docs-new/layouts/_default/release_notes.html @@ -11,7 +11,6 @@ {{ if or (hugo.IsProduction) ( eq hugo.Environment "staging") ( eq hugo.Environment "branch-deploy")}} {{ with $product := $.Param "release_notes" }} - {{- $versionsUrl := "" -}} {{- if eq $product "automate" -}} {{- $versionsUrl = "https://packages.chef.io/releases/current/automate.json"}} @@ -23,7 +22,26 @@ {{- $versionsUrl = (print "https://omnitruck.chef.io/stable/" $product "/versions/all") -}} {{- end -}} - {{- $versions := getJSON $versionsUrl -}} + {{ $versions := "" }} + + {{ $headers := dict "Cache-Control" "no-cache" "Connection" "keep-alive" }} + {{ $cacheKey := print $versionsUrl (now.Format "20060102") (div now.Hour 6) | md5 }} + {{ $opts := dict "headers" $headers "key" $cacheKey }} + + {{- if hasPrefix $versionsUrl "https://" -}} + {{- with resources.GetRemote $versionsUrl $opts -}} + {{ with .Err }} + {{ errorf "%s" . }} + {{ else }} + {{ $unmarshalOpts := dict "delimiter" "," }} + {{ $versions = . | transform.Unmarshal $unmarshalOpts }} + {{ end }} + {{ else }} + {{ errorf "Unable to get remote resource %q" $versionsUrl }} + {{ end }} + {{ else }} + {{ $versions = getJSON $versionsUrl }} + {{ end }} {{/* We have a "current" version of Infra Client that they want release notes for on the Client release notes page. */}} {{/* This allows us to add current release version numbers of Client to the list of version numbers */}} @@ -102,7 +120,12 @@

{{ $fullName }} {{ $version }}

Released on {{ time.Format "January 2, 2006" .release_date }}

{{- end -}} - {{- $remoteResponse := resources.GetRemote $mdUrl (dict "headers" (dict "Cache-Control" "no-cache" "Connection" "keep-alive")) -}} + {{/* Define GetRemote options */}} + {{ $headers := dict "Cache-Control" "no-cache" "Connection" "keep-alive" }} + {{ $cacheKey := print $mdUrl (now.Format "20060102") (div now.Hour 6) | md5 }} + {{ $opts := dict "headers" $headers "key" $cacheKey }} + + {{- $remoteResponse := resources.GetRemote $mdUrl $opts -}} {{- if eq $remoteResponse nil -}}

This release does not have any release notes.

diff --git a/themes/docs-new/layouts/partials/release_notes_toc.html b/themes/docs-new/layouts/partials/release_notes_toc.html index a9d6be2dc6..6c6bc29c69 100644 --- a/themes/docs-new/layouts/partials/release_notes_toc.html +++ b/themes/docs-new/layouts/partials/release_notes_toc.html @@ -21,7 +21,26 @@ {{ $versionsUrl = (print "https://omnitruck.chef.io/stable/" $product "/versions/all") }} {{ end }} - {{ $versions := getJSON $versionsUrl }} + {{ $versions := "" }} + + {{ $headers := dict "Cache-Control" "no-cache" "Connection" "keep-alive" }} + {{ $cacheKey := print $versionsUrl (now.Format "20060102") (div now.Hour 6) | md5 }} + {{ $opts := dict "headers" $headers "key" $cacheKey }} + + {{- if hasPrefix $versionsUrl "https://" -}} + {{- with resources.GetRemote $versionsUrl $opts -}} + {{ with .Err }} + {{ errorf "%s" . }} + {{ else }} + {{ $unmarshalOpts := dict "delimiter" "," }} + {{ $versions = . | transform.Unmarshal $unmarshalOpts }} + {{ end }} + {{ else }} + {{ errorf "Unable to get remote resource %q" $versionsUrl }} + {{ end }} + {{ else }} + {{ $versions = getJSON $versionsUrl }} + {{ end }} {{/* We have a current version of Infra Client that they want release notes for on the Client release notes page. */}} {{/* This allows us to add current release version numbers of Client to the list of version numbers */}}