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 via the Setup() function, which initializes the cache strategy, configures static file serving, and registers your file-based routes — all in one call.
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 Setup() function 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 main.go using Cache Control Headers:
package main
import (
"log"
"log/slog"
"net/http"
"os"
"your-module/src/routes"
gothicRoutes "github.com/felipegenef/gothicframework/v2/pkg/helpers/routes"
"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)
gothicRoutes. Setup (router, gothicRoutes. AppConfig {
CacheStrategy: gothicRoutes. CACHE_CONTROL_HEADERS ,
ServeStaticFiles: gothicRoutes. HOT_RELOAD_ONLY ,
}, routes.RegisterFileBasedRoutes)
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!