Cache Control Headers
The Gothic Framework provides a built-in pluggable cache system that handles page and API response caching with multiple strategy options. You configure the cache in the Runtime block of your gothic.config.go file, which sets the cache strategy and static file serving. The runtime Middleware then applies that configuration, and RegisterFileBasedRoutes wires up your file-based routes.
CACHE_CONTROL_HEADERS is the default strategy. It does not store cached data in your application. Instead, it sets Cache-Control headers on responses so that a CDN (like AWS CloudFront) caches them at the edge. This is the recommended strategy for AWS deployments with the Gothic deploy tool.
The runtime Middleware reads the GOTHIC_MODE environment variable. Set GOTHIC_MODE=dev in your .env file for local development. When absent or set to any other value, the application runs in production mode.
Here is a typical gothic.config.go using Cache Control Headers:
package main
import gothic "github.com/gothicframework/core/config"
var Config = gothic.Config{
ProjectName: "my-project",
Runtime: gothic.RuntimeConfig{
CacheStrategy: gothic.CACHE_CONTROL_HEADERS,
LocalDevelopmentCache: gothic.IN_MEMORY,
ServeStaticFiles: gothic.HOT_RELOAD_ONLY,
},
}And here is the main.go that applies it with the runtime Middleware:
package main
import (
"log"
"log/slog"
"net/http"
"os"
"your-module/src/routes"
gothicServer "github.com/gothicframework/middlewares"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
router := chi.NewMux()
router.Use(middleware.Logger)
router.Use(gothicServer.Middleware(Config.Runtime))
routes.RegisterFileBasedRoutes(router)
port := os.Getenv("HTTP_LISTEN_ADDR")
slog.Info("application running", "port", port)
log.Fatal(http.ListenAndServe(port, router))
}ServeStaticFiles controls when /public/* files are served from disk. HOT_RELOAD_ONLY (default) serves them only in dev mode — in production, CloudFront serves static assets from S3. Use ALL_ENVS for Docker or non-AWS deployments.
Want to cache pages directly in your application without a CDN? Check out the In Memory cache strategy!
