Home / Function/ Test_CacheOnlyIfCachedStaleNotServed() — fiber Function Reference

Test_CacheOnlyIfCachedStaleNotServed() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 1919–1945

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

	app := fiber.New()
	app.Use(New())

	var count int
	app.Get("/", func(c fiber.Ctx) error {
		count++
		c.Set(fiber.HeaderCacheControl, "public, max-age=1")
		return c.SendString(strconv.Itoa(count))
	})

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

	time.Sleep(1500 * time.Millisecond)

	req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
	req.Header.Set(fiber.HeaderCacheControl, "only-if-cached")
	resp, err = app.Test(req)
	require.NoError(t, err)
	require.Equal(t, fiber.StatusGatewayTimeout, resp.StatusCode)
	require.Equal(t, cacheUnreachable, resp.Header.Get("X-Cache"))
	require.Equal(t, 1, count)
}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free