Skip to content

Commit e89a181

Browse files
author
Chris Stockton
committed
feat: load template cache at startup for fault tolerance
When template reloading is disabled start a goroutine to warm the template cache early in startup.
1 parent 4be12b3 commit e89a181

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/serve_cmd.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ func serve(ctx context.Context) {
6363
defer wg.Wait() // Do not return to caller until this goroutine is done.
6464

6565
mrCache := templatemailer.NewCache()
66+
if !config.Mailer.TemplateReloadingEnabled {
67+
// If template reloading is disabled attempt an initial reload at
68+
// startup for fault tolerance.
69+
wg.Add(1)
70+
defer func() {
71+
defer wg.Done()
72+
73+
mrCache.Reload(ctx, config)
74+
}()
75+
}
76+
6677
limiterOpts := api.NewLimiterOptions(config)
6778
initialAPI := api.NewAPIWithVersion(
6879
config, db, utilities.Version,

0 commit comments

Comments
 (0)