Home / Function/ Test_Cache_CacheControlCombinations() — fiber Function Reference

Test_Cache_CacheControlCombinations() — fiber Function Reference

Architecture documentation for the Test_Cache_CacheControlCombinations() function in cache_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  fe9c1a35_931d_df40_e842_e714def3b7ef["Test_Cache_CacheControlCombinations()"]
  8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"]
  fe9c1a35_931d_df40_e842_e714def3b7ef -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656
  style fe9c1a35_931d_df40_e842_e714def3b7ef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 4289–4528

func Test_Cache_CacheControlCombinations(t *testing.T) {
	t.Parallel()

	t.Run("max-age with public", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Cache-Control", "public, max-age=3600")
			return c.SendString("public content")
		})

		rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheMiss, rsp.Header.Get("X-Cache"))

		rsp2, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheHit, rsp2.Header.Get("X-Cache"))
	})

	t.Run("max-age with private", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Cache-Control", "private, max-age=3600")
			return c.SendString("private content")
		})

		rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheUnreachable, rsp.Header.Get("X-Cache"))
	})

	t.Run("s-maxage overrides max-age", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Cache-Control", "public, max-age=60, s-maxage=3600")
			return c.SendString("content")
		})

		rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheMiss, rsp.Header.Get("X-Cache"))

		rsp2, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheHit, rsp2.Header.Get("X-Cache"))
	})

	t.Run("no-store prevents caching", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Cache-Control", "no-store")
			return c.SendString("no store content")
		})

		rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheUnreachable, rsp.Header.Get("X-Cache"))

		rsp2, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
		require.NoError(t, err)
		require.Equal(t, cacheUnreachable, rsp2.Header.Get("X-Cache"))
	})

	t.Run("no-cache with etag", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Cache-Control", "no-cache")
			c.Response().Header.Set("ETag", `"123456"`)
			return c.SendString("no-cache content")
		})

Subdomains

Frequently Asked Questions

What does Test_Cache_CacheControlCombinations() do?
Test_Cache_CacheControlCombinations() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_Cache_CacheControlCombinations() defined?
Test_Cache_CacheControlCombinations() is defined in middleware/cache/cache_test.go at line 4289.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free